mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
feat: fut: add spawn_on_current_runner
This commit is contained in:
parent
0a432585c6
commit
9cb7781a2e
2 changed files with 14 additions and 0 deletions
|
|
@ -100,6 +100,11 @@ let spawn ~on f : _ t =
|
|||
Runner.run_async on task;
|
||||
fut
|
||||
|
||||
let spawn_on_current_runner f : _ t =
|
||||
match Runner.get_current_runner () with
|
||||
| None -> failwith "Fut.spawn_on_current_runner: not running on a runner"
|
||||
| Some on -> spawn ~on f
|
||||
|
||||
let reify_error (f : 'a t) : 'a or_error t =
|
||||
match peek f with
|
||||
| Some res -> return res
|
||||
|
|
|
|||
|
|
@ -85,6 +85,15 @@ val spawn : on:Runner.t -> (unit -> 'a) -> 'a t
|
|||
(** [spaw ~on f] runs [f()] on the given runner [on], and return a future that will
|
||||
hold its result. *)
|
||||
|
||||
val spawn_on_current_runner : (unit -> 'a) -> 'a t
|
||||
(** This must be run from inside a runner, and schedules
|
||||
the new task on it as well.
|
||||
|
||||
See {!Runner.get_current_runner} to see how the runner is found.
|
||||
|
||||
@since NEXT_RELEASE
|
||||
@raise Failure if run from outside a runner. *)
|
||||
|
||||
val reify_error : 'a t -> 'a or_error t
|
||||
(** [reify_error fut] turns a failing future into a non-failing
|
||||
one that contain [Error (exn, bt)]. A non-failing future
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue