diff --git a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs index a883b2ecf5..da9c8b858d 100644 --- a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs +++ b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs @@ -162,7 +162,22 @@ type AsyncType() = this.WaitASec t Assert.IsTrue (t.IsCompleted) Assert.AreEqual(s, t.Result) - + + [] + member this.RunSynchronouslyCancellationWithDelayedResult () = + let cts = new CancellationTokenSource() + let tcs = TaskCompletionSource() + 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 -> () + [] member this.ExceptionPropagatesToTask () = let a = async { diff --git a/src/fsharp/FSharp.Core/control.fs b/src/fsharp/FSharp.Core/control.fs index e8231ecfaf..05554c813e 100644 --- a/src/fsharp/FSharp.Core/control.fs +++ b/src/fsharp/FSharp.Core/control.fs @@ -1536,14 +1536,6 @@ namespace Microsoft.FSharp.Control // Contains helpers that will attach continuation to the given task. // Should be invoked as a part of protectedPrimitive(withResync) call module TaskHelpers = - let private continueWithExtra token = -#if FSCORE_PORTABLE_OLD || FSCORE_PORTABLE_NEW - token |> ignore - TaskContinuationOptions.None -#else - token -#endif - let continueWith (task : Task<'T>, args, useCcontForTaskCancellation) = let continuation (completedTask : Task<_>) : unit = @@ -1557,7 +1549,7 @@ namespace Microsoft.FSharp.Control else args.cont completedTask.Result)) |> unfake - task.ContinueWith(Action>(continuation), continueWithExtra args.aux.token) |> ignore |> fake + task.ContinueWith(Action>(continuation)) |> ignore |> fake let continueWithUnit (task : Task, args, useCcontForTaskCancellation) = @@ -1572,7 +1564,7 @@ namespace Microsoft.FSharp.Control else args.cont ())) |> unfake - task.ContinueWith(Action(continuation), continueWithExtra args.aux.token) |> ignore |> fake + task.ContinueWith(Action(continuation)) |> ignore |> fake #endif #if FX_NO_REGISTERED_WAIT_HANDLES