TaskEx: Async.startImmediateAsTask
Replaces https://github.com/fsprojects/FSharp.Control.TaskSeq/issues/129. TaskShims top level issue: https://github.com/fsprojects/FSharp.Control.TaskSeq/issues/139
In contrast to its sibling, Async.StartAsTask (because it is not starting a thread), Async.StartImmediateAsTask does not have a taskCreationOptions optional parameter, so people often use it pipeline expressions.
However, that makes it easy to gloss over the fact that the computation will then not have an ambient cancellation token.
In order to resolve those forces (wanting to be able to execute an async via piping, without the risk of omitting to consider cancelation), it is proposed to have a common helper function (with a lower case name) that
- takes a cancellation token (as its first argument)
- passes that and the Async onto
Async.StartImmediateAsTask
Current proposed APIs (will be updated inline based on any discussion below):
module Async =
let inline startImmediateAsTask ct (a : Async<'t>) = Async.StartImmediateAsTask(a, cancellationToken = ct)
// ALTERNATELY
let inline executeAsTask ct (a : Async<'t>) = Async.StartImmediateAsTask(a, cancellationToken = ct)
NOTES:
- This is useful both within applications, and internally within libraries