Skip to content

Commit c6a070b

Browse files
matthiddsyme
authored andcommitted
add test and fix #3254 (#3255)
* add test and fix #3254 * remove continueWithExtra * add timeout attribute * don't delegate the cancellationtoken to the operationcancelledexception. * Revert "add timeout attribute" This reverts commit aeeaa50. * Update control.fs
1 parent c9f9a6d commit c6a070b

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff 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 {

src/fsharp/FSharp.Core/control.fs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)