Skip to content

Commit 62b9714

Browse files
authored
Merge pull request #806 from dialohq/main
Prioritize returning Fiber.any value over cancelling quickly
2 parents 1dce15f + 82e5e1e commit 62b9714

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib_eio/core/fiber.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ let any_gen ~return ~combine fs =
150150
)
151151
in
152152
match !r, Cancel.get_error parent_c with
153-
| OK r, None -> r
154-
| (OK _ | New), Some ex -> raise ex
153+
| OK r, _ -> r
154+
| New, Some ex -> raise ex
155155
| Ex (ex, bt), None -> Printexc.raise_with_backtrace ex bt
156156
| Ex ex1, Some ex2 ->
157157
let bt2 = Printexc.get_raw_backtrace () in

tests/fiber.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,23 @@ Cancelled from parent:
191191
Exception: Failure "Parent cancel".
192192
```
193193

194-
Cancelled from parent while already cancelling:
194+
Cancelled from parent while already cancelling
195+
(we return the value despite the cancellation):
195196

196197
```ocaml
197198
# run @@ fun () ->
198199
Fiber.both
199200
(fun () ->
200-
let _ = Fiber.first
201+
traceln "%s" @@ Fiber.first
201202
(fun () -> "a")
202-
(fun () -> Fiber.yield (); failwith "cancel-b")
203-
in
203+
(fun () -> Fiber.yield (); failwith "cancel-b");
204+
Fiber.check ();
204205
traceln "Parent cancel failed"
205206
)
206207
(fun () -> traceln "Cancelling parent"; failwith "Parent cancel");
207208
"not-reached";;
208209
+Cancelling parent
210+
+a
209211
Exception: Failure "Parent cancel".
210212
```
211213

0 commit comments

Comments
 (0)