Skip to content

Commit 26e284c

Browse files
committed
always handle cancellations
1 parent 172dc31 commit 26e284c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/Compiler/Utilities/Cancellable.fs

Lines changed: 10 additions & 10 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 ->
@@ -96,19 +100,15 @@ module Cancellable =
96100

97101
let toAsync c =
98102
async {
99-
use! _holder = Cancellable.UseToken()
103+
use! _ = Cancellable.UseToken()
100104

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)