eio icon indicating copy to clipboard operation
eio copied to clipboard

Feature request: Stream select

Open dermesser opened this issue 1 year ago • 6 comments

Thank you very much for your work on eio! I've thoroughly enjoyed working with it, despite being a newcomer to OCaml. Eio feels more advanced than the async frameworks in other languages I've used.

So far, I have been missing one feature: Waiting on multiple streams, which in languages like Go or Rust is called select. I've taken a look at the source code, but as a newbie I didn't want to charge ahead with some untenable solution (and besides, any possible implementation appeared non-trivial to me).

I don't have a specific API in mind, but something simple like

val select : ('a Stream.t * ('a -> 'b)) list -> 'b

to select between different channels producing items of the same type and permitting per-stream handling, or

val select2 : 'a Stream.t -> 'b Stream.t -> ('a, 'b) Either.t

for selecting between exactly two streams may already prove to be useful. I'd love to hear what you think.

dermesser avatar Jul 08 '23 19:07 dermesser