mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
add ?on param to Fiber.spawn
This commit is contained in:
parent
f798420423
commit
f9aea68d61
2 changed files with 10 additions and 3 deletions
|
|
@ -265,7 +265,7 @@ let spawn_top ~on f : _ t =
|
|||
let ls = Task_local_storage.Direct.create () in
|
||||
spawn_ ~ls ~runner:on ~parent:None f
|
||||
|
||||
let spawn ?(protect = true) f : _ t =
|
||||
let spawn ?on ?(protect = true) f : _ t =
|
||||
(* spawn [f()] with a copy of our local storage *)
|
||||
let (Any p) =
|
||||
match get_cur () with
|
||||
|
|
@ -273,7 +273,12 @@ let spawn ?(protect = true) f : _ t =
|
|||
| Some p -> p
|
||||
in
|
||||
let ls = Task_local_storage.Direct.copy p.ls in
|
||||
let child = spawn_ ~ls ~parent:(Some p) ~runner:p.runner f in
|
||||
let runner =
|
||||
match on with
|
||||
| Some r -> r
|
||||
| None -> p.runner
|
||||
in
|
||||
let child = spawn_ ~ls ~parent:(Some p) ~runner f in
|
||||
add_child_ ~protect p child;
|
||||
child
|
||||
|
||||
|
|
|
|||
|
|
@ -120,12 +120,14 @@ val spawn_top : on:Runner.t -> (unit -> 'a) -> 'a t
|
|||
This fiber is not the child of any other fiber: its lifetime
|
||||
is only determined by the lifetime of [f()]. *)
|
||||
|
||||
val spawn : ?protect:bool -> (unit -> 'a) -> 'a t
|
||||
val spawn : ?on:Runner.t -> ?protect:bool -> (unit -> 'a) -> 'a t
|
||||
(** [spawn ~protect f] spawns a sub-fiber [f_child]
|
||||
from a running fiber [parent].
|
||||
The sub-fiber [f_child] is attached to the current fiber and fails
|
||||
if the current fiber [parent] fails.
|
||||
|
||||
@param on if provided, start the fiber on the given runner. If not
|
||||
provided, use the parent's runner.
|
||||
@param protect if true, when [f_child] fails, it does not
|
||||
affect [parent]. If false, [f_child] failing also
|
||||
causes [parent] to fail (and therefore all other children
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue