@@ -767,7 +767,7 @@ namespace Microsoft.FSharp.Control
767767
768768 // Call the cancellation continuation
769769 let cancelT ( args : AsyncParams < _ >) =
770- args.aux.ccont ( new OperationCanceledException())
770+ args.aux.ccont ( new OperationCanceledException( args.aux.token ))
771771
772772 // Build a primitive without any exception of resync protection
773773 //
@@ -1541,8 +1541,8 @@ namespace Microsoft.FSharp.Control
15411541 let continuation ( completedTask : Task < _ >) : unit =
15421542 args.aux.trampolineHolder.Protect(( fun () ->
15431543 if completedTask.IsCanceled then
1544- if useCcontForTaskCancellation then args.aux.ccont( new OperationCanceledException())
1545- else args.aux.econt ( ExceptionDispatchInfo.Capture( new TaskCanceledException()))
1544+ if useCcontForTaskCancellation then args.aux.ccont( new OperationCanceledException( args.aux.token ))
1545+ else args.aux.econt ( ExceptionDispatchInfo.Capture( new TaskCanceledException( completedTask )))
15461546 elif completedTask.IsFaulted then
15471547 args.aux.econt ( MayLoseStackTrace( completedTask.Exception))
15481548 else
@@ -1555,8 +1555,8 @@ namespace Microsoft.FSharp.Control
15551555 let continuation ( completedTask : Task ) : unit =
15561556 args.aux.trampolineHolder.Protect(( fun () ->
15571557 if completedTask.IsCanceled then
1558- if useCcontForTaskCancellation then args.aux.ccont ( new OperationCanceledException())
1559- else args.aux.econt ( ExceptionDispatchInfo.Capture( new TaskCanceledException()))
1558+ if useCcontForTaskCancellation then args.aux.ccont ( new OperationCanceledException( args.aux.token ))
1559+ else args.aux.econt ( ExceptionDispatchInfo.Capture( new TaskCanceledException( completedTask )))
15601560 elif completedTask.IsFaulted then
15611561 args.aux.econt ( MayLoseStackTrace( completedTask.Exception))
15621562 else
@@ -1630,7 +1630,7 @@ namespace Microsoft.FSharp.Control
16301630 match ! timer with
16311631 | None -> ()
16321632 | Some t -> t.Dispose()
1633- aux.trampolineHolder.Protect( fun () -> savedCCont( new OperationCanceledException())) |> unfake
1633+ aux.trampolineHolder.Protect( fun () -> savedCCont( new OperationCanceledException( aux.token ))) |> unfake
16341634 ),
16351635 null )
16361636 let mutable edi = null
@@ -1695,7 +1695,7 @@ namespace Microsoft.FSharp.Control
16951695 Async.Start ( async { do ( ccont e |> unfake) })
16961696
16971697 // register cancellation handler
1698- let registration = aux.token.Register( fun () -> cancel ( OperationCanceledException()))
1698+ let registration = aux.token.Register( fun () -> cancel ( OperationCanceledException( aux.token )))
16991699
17001700 // run actual await routine
17011701 // callback will be executed on the thread pool so we need to use TrampolineHolder.Protect to install trampoline
@@ -1746,7 +1746,7 @@ namespace Microsoft.FSharp.Control
17461746 match ! rwh with
17471747 | None -> ()
17481748 | Some rwh -> rwh.Unregister( null ) |> ignore)
1749- Async.Start ( async { do ( aux.ccont ( OperationCanceledException()) |> unfake) }))
1749+ Async.Start ( async { do ( aux.ccont ( OperationCanceledException( aux.token )) |> unfake) }))
17501750
17511751 and registration : CancellationTokenRegistration = aux.token.Register( cancelHandler, null )
17521752
@@ -1842,7 +1842,7 @@ namespace Microsoft.FSharp.Control
18421842 // Register the result. This may race with a successful result, but
18431843 // ResultCell allows a race and throws away whichever comes last.
18441844 once.Do( fun () ->
1845- let canceledResult = Canceled ( OperationCanceledException())
1845+ let canceledResult = Canceled ( OperationCanceledException( cancellationToken ))
18461846 resultCell.RegisterResult( canceledResult, reuseThread= true ) |> unfake
18471847 )
18481848 | Some cancel ->
@@ -2007,7 +2007,7 @@ namespace Microsoft.FSharp.Control
20072007 event.RemoveHandler( del)
20082008 // Register the result. This may race with a successful result, but
20092009 // ResultCell allows a race and throws away whichever comes last.
2010- once.Do( fun () -> resultCell.RegisterResult( Canceled ( OperationCanceledException()), reuseThread= true ) |> unfake)
2010+ once.Do( fun () -> resultCell.RegisterResult( Canceled ( OperationCanceledException( token )), reuseThread= true ) |> unfake)
20112011 | Some cancel ->
20122012 // If we get an exception from a cooperative cancellation function
20132013 // we assume the operation has already completed.
0 commit comments