Skip to content

How to change CancellationToken in EnvIO? #1409

Answered by louthy
rvahitov asked this question in Q&A
Discussion options

You must be logged in to vote

The EnvIO is optional:

public static ValueTask<Fin<A>> RunSafeAsync<A>(this K<IO, A> ma, EnvIO? envIO = null) =>
    ma.As().Try().Run().RunAsync(envIO);

So you can provide your own with your own CancellationToken:

using var envIO = EnvIO.New(cancellationToken);
var fin = await io.RunSafeAsync(envIO)

By the way, not sure if this just example code, but I would separate out your IO functionality:

public IO<CompanyDTO> FindCompanyById(string id) =>
    from entity in DB.FinCompanyById(id) 
                   | @catch(IO<CompanyEntity>.Fail(InternalError))
    from dto in entity.MapToDto()
    select dto;

And create an extension to do the 'messy stuff':

public static async Task<IResult> RunTo…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rvahitov
Comment options

Answer selected by rvahitov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants