Skip to content

Commit c7dfacf

Browse files
committed
Merge pull request #272 from panesofglass/master
Add Async and AsyncBuilder extensions for working with non-generic Tasks
2 parents 33a0d85 + 314bfde commit c7dfacf

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/FSharpx.Core/Async.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ module AsyncExtensions =
3838

3939
#if NET40
4040

41+
/// Starts a non-generic Task with the cancellationToken and returns an
42+
/// Async<unit> containing the result.
43+
static member AwaitTask(task:Tasks.Task, ?cancellationToken) =
44+
let cancel = defaultArg cancellationToken Async.DefaultCancellationToken
45+
Async.AwaitTask <| task.ContinueWith((fun t -> ()), cancel)
46+
4147
/// Starts a Task<'a> with the timeout and cancellationToken and
4248
/// returns a Async<a' option> containing the result. If the Task does
4349
/// not complete in the timeout interval, or is faulted None is returned.
@@ -54,6 +60,7 @@ module AsyncExtensions =
5460
/// 'Bind' of the 'async' builder. The new overload awaits on
5561
/// a standard .NET task
5662
type Microsoft.FSharp.Control.AsyncBuilder with
57-
member x.Bind(t:Tasks.Task<'T>, f:'T -> Async<'R>) : Async<'R> = async.Bind(Async.AwaitTask t, f)
63+
member x.Bind(t:Tasks.Task<'T>, f:'T -> Async<'R>) : Async<'R> = async.Bind(Async.AwaitTask t, f)
64+
member x.Bind(t:Tasks.Task, f:unit -> Async<'R>) : Async<'R> = async.Bind(Async.AwaitTask t, f)
5865

5966
#endif

0 commit comments

Comments
 (0)