File tree Expand file tree Collapse file tree 2 files changed +18
-11
lines changed
FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,22 @@ type AsyncType() =
162162 this.WaitASec t
163163 Assert.IsTrue ( t.IsCompleted)
164164 Assert.AreEqual( s, t.Result)
165-
165+
166+ [<Test>]
167+ member this.RunSynchronouslyCancellationWithDelayedResult () =
168+ let cts = new CancellationTokenSource()
169+ let tcs = TaskCompletionSource< int>()
170+ let _ = cts.Token.Register( fun () -> tcs.SetResult 42 )
171+ let a = async {
172+ cts.CancelAfter ( 100 )
173+ let! result = tcs.Task |> Async.AwaitTask
174+ return result }
175+
176+ try
177+ Async.RunSynchronously( a, cancellationToken = cts.Token)
178+ |> ignore
179+ with :? OperationCanceledException as o -> ()
180+
166181 [<Test>]
167182 member this.ExceptionPropagatesToTask () =
168183 let a = async {
Original file line number Diff line number Diff line change @@ -1536,14 +1536,6 @@ namespace Microsoft.FSharp.Control
15361536 // Contains helpers that will attach continuation to the given task.
15371537 // Should be invoked as a part of protectedPrimitive(withResync) call
15381538 module TaskHelpers =
1539- let private continueWithExtra token =
1540- #if FSCORE_ PORTABLE_ OLD || FSCORE_ PORTABLE_ NEW
1541- token |> ignore
1542- TaskContinuationOptions.None
1543- #else
1544- token
1545- #endif
1546-
15471539 let continueWith ( task : Task < 'T >, args , useCcontForTaskCancellation ) =
15481540
15491541 let continuation ( completedTask : Task < _ >) : unit =
@@ -1557,7 +1549,7 @@ namespace Microsoft.FSharp.Control
15571549 else
15581550 args.cont completedTask.Result)) |> unfake
15591551
1560- task.ContinueWith( Action< Task< 'T>>( continuation), continueWithExtra args.aux.token ) |> ignore |> fake
1552+ task.ContinueWith( Action< Task< 'T>>( continuation)) |> ignore |> fake
15611553
15621554 let continueWithUnit ( task : Task , args , useCcontForTaskCancellation ) =
15631555
@@ -1572,7 +1564,7 @@ namespace Microsoft.FSharp.Control
15721564 else
15731565 args.cont ())) |> unfake
15741566
1575- task.ContinueWith( Action< Task>( continuation), continueWithExtra args.aux.token ) |> ignore |> fake
1567+ task.ContinueWith( Action< Task>( continuation)) |> ignore |> fake
15761568#endif
15771569
15781570#if FX_ NO_ REGISTERED_ WAIT_ HANDLES
You can’t perform that action at this time.
0 commit comments