Skip to content

Commit

Permalink
add test and fix dotnet#3254
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Jun 24, 2017
1 parent a29abe3 commit 3d0d28a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,22 @@ type AsyncType() =
this.WaitASec t
Assert.IsTrue (t.IsCompleted)
Assert.AreEqual(s, t.Result)


[<Test>]
member this.RunSynchronouslyCancellationWithDelayedResult () =
let cts = new CancellationTokenSource()
let tcs = TaskCompletionSource<int>()
let _ = cts.Token.Register(fun () -> tcs.SetResult 42)
let a = async {
cts.CancelAfter (100)
let! result = tcs.Task |> Async.AwaitTask
return result }

try
Async.RunSynchronously(a, cancellationToken = cts.Token)
|> ignore
with :? OperationCanceledException as o -> ()

[<Test>]
member this.ExceptionPropagatesToTask () =
let a = async {
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/FSharp.Core/control.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ namespace Microsoft.FSharp.Control
else
args.cont completedTask.Result)) |> unfake

task.ContinueWith(Action<Task<'T>>(continuation), continueWithExtra args.aux.token) |> ignore |> fake
task.ContinueWith(Action<Task<'T>>(continuation)) |> ignore |> fake

let continueWithUnit (task : Task, args, useCcontForTaskCancellation) =

Expand All @@ -1572,7 +1572,7 @@ namespace Microsoft.FSharp.Control
else
args.cont ())) |> unfake

task.ContinueWith(Action<Task>(continuation), continueWithExtra args.aux.token) |> ignore |> fake
task.ContinueWith(Action<Task>(continuation)) |> ignore |> fake
#endif

#if FX_NO_REGISTERED_WAIT_HANDLES
Expand Down

0 comments on commit 3d0d28a

Please sign in to comment.