I have an Async<'T>
computation that I want to run, and obtain the result 'T
.
I only have two requirements:
- After certain
timeout:TimeSpan
has passed, I want the computation/IO to be aborted. - I want to run it with a
cancellationToken
just in case I want to abort it beforetimeout
has passed.
According to my requirement (1) above, you might think that Async.StartChild
is a good candidate because it accepts a timeout parameter, however, it doesn't accept a cancellationToken parameter!
It seems that the other Async.
methods in the API that accept a cancellationToken either don't return anything (so I cannot await for the result), or only work for Async<unit>
, or don't allow me a way to combine it with Async.StartChild to achieve both of my requirements.
Also, I need to implement this inside an async{}
block, which means that using Async.RunSynchronously
inside it (just in case you suggest this) would look either problematic or ugly.
Am I overlooking anything?
Thanks!