Skip to content

Commit 29bcaf1

Browse files
authored
Cancellable: always catch internal cancellations (#18531)
1 parent 9e74c0e commit 29bcaf1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Compiler/Utilities/Cancellable.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ module Cancellable =
7373
if ct.IsCancellationRequested then
7474
ValueOrCancelled.Cancelled(OperationCanceledException ct)
7575
else
76-
oper ct
76+
try
77+
oper ct
78+
with
79+
| :? OperationCanceledException as e when ct.IsCancellationRequested -> ValueOrCancelled.Cancelled e
80+
| :? OperationCanceledException as e -> InvalidOperationException("Wrong cancellation token", e) |> raise
7781

7882
let fold f acc seq =
7983
Cancellable(fun ct ->
@@ -101,14 +105,10 @@ module Cancellable =
101105
let! ct = Async.CancellationToken
102106

103107
return!
104-
Async.FromContinuations(fun (cont, econt, ccont) ->
105-
try
106-
match run ct c with
107-
| ValueOrCancelled.Value v -> cont v
108-
| ValueOrCancelled.Cancelled ce -> ccont ce
109-
with
110-
| :? OperationCanceledException as ce when ct.IsCancellationRequested -> ccont ce
111-
| :? OperationCanceledException as e -> InvalidOperationException("Wrong cancellation token", e) |> econt)
108+
Async.FromContinuations(fun (cont, _econt, ccont) ->
109+
match run ct c with
110+
| ValueOrCancelled.Value v -> cont v
111+
| ValueOrCancelled.Cancelled ce -> ccont ce)
112112
}
113113

114114
let token () = Cancellable(ValueOrCancelled.Value)

0 commit comments

Comments
 (0)