Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eio_luv: Losing effect handler scope #427

Closed
patricoferris opened this issue Jan 30, 2023 · 3 comments
Closed

eio_luv: Losing effect handler scope #427

patricoferris opened this issue Jan 30, 2023 · 3 comments

Comments

@patricoferris
Copy link
Collaborator

This is an issue formed out of https://discuss.ocaml.org/t/how-to-compose-effect-handlers-with-eio/11279 and is reproducible with this small program.

module Echo = struct
  type _ Effect.t += Echo : string -> unit Effect.t

  let run f =
    Effect.Deep.try_with f ()
      {
        effc =
          (fun (type b) (eff : b Effect.t) ->
            match eff with
            | Echo string ->
                Some
                  (fun (k : (b, unit) Effect.Deep.continuation) ->
                    print_endline string;
                    Effect.Deep.continue k ())
            | _ -> None);
      }
end

let () =
  Echo.run @@ fun () ->
  Eio_main.run @@ fun _ ->
  Eio.Fiber.yield ();
  Effect.perform (Echo.Echo "world")

We define a new effect, Echo, and provide a simple handler (this is a contrived example). We would expect that all effects in this program would be handled but actually using Eio_luv the Echo effect is unhandled. I think this is due to the wakeup happening as a callback in the Luv.Async object.

@talex5
Copy link
Collaborator

talex5 commented Jan 30, 2023

It's because you can't perform an effect over a C function call. So effects performed inside libuv's run function can't be handled by an effect handler outside it.

@wokalski
Copy link

I think an explicit API to inject handlers either on the Fiber or Switch level would be great here.

@patricoferris
Copy link
Collaborator Author

I think an explicit API to inject handlers either on the Fiber or Switch level would be great here

Note that this issue is not about that problem, this is just a bug in Eio_luv due to an implementation detail. If you have time I would create a separate issue for the API for injecting handlers. I think it would also be super helpful to have a non-contrived example that can't be achieved with functions and fiber local storage or functors as part of that issue which will help with getting a design in mind :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants