Skip to content

Commit

Permalink
refactor: split effect execution with exec/exec_eff (#38)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Apr 9, 2024
1 parent 68e934c commit f8973fb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fiber/src/scheduler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,14 @@ and loop2 a b =
and exec : 'a. context -> ('a -> eff) -> 'a -> Jobs.t -> step' =
fun ctx k x jobs ->
match k x with
| eff -> exec_eff ctx eff jobs
| exception exn ->
let exn = Exn_with_backtrace.capture exn in
exec ctx.on_error.ctx ctx.on_error.run exn jobs

and exec_eff : 'a. context -> 'eff -> Jobs.t -> step' =
fun ctx x jobs ->
match x with
| Done v -> Done v
| Toplevel_exception exn -> Exn_with_backtrace.reraise exn
| Unwind (k, x) -> exec ctx.parent k x jobs
Expand Down Expand Up @@ -121,7 +126,7 @@ and exec : 'a. context -> ('a -> eff) -> 'a -> Jobs.t -> step' =
| Fork (a, b) ->
let (Map_reduce_context r) = ctx.map_reduce_context in
r.ref_count <- r.ref_count + 1;
exec ctx Fun.id a (Job (ctx, b, (), jobs))
exec_eff ctx a (Job (ctx, b, (), jobs))
| Reraise exn ->
let { ctx; run } = ctx.on_error in
exec ctx run exn jobs
Expand Down

0 comments on commit f8973fb

Please sign in to comment.