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

Stream select #578

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

dermesser
Copy link

(for #577)

This is a proposal for a (simplistic) implementation of Stream.select, which permits watching multiple streams and returning the first item yielded by any of them. It works for the intended use case, although at this point there are two weaknesses, both due to the underlying implementation using Fiber.any:

  • Only streams of the same item type can be selected across (just like Fiber.any only works with fiber functions yielding the same type)
  • If two or more streams are ready at the same time, all but one elements will be discarded (just like Fiber.any). This is documented, but still not desirable.

Thanks for considering this - I'd be happy to hear proposals for making this functionality more general, or just not based on the Fiber functions which restrict what can be done here. So please consider it a starting point :-)

Comment on lines +48 to +50
Warning: as with `Fiber.first`, it is possible that two or more streams
yield an item simultaneously, in which case only one item will be
returned, and the other items are discarded.*)
Copy link
Collaborator

@SGrondin SGrondin Jul 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this caveat is too much at the moment.
I would love to see Eio.Stream.select added, but I think it needs to be done using something like #558

Copy link
Collaborator

@talex5 talex5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for prototyping this! As @SGrondin says, if we have this then it needs to be atomic (discussion is continuing in the original issue at #577).

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

Successfully merging this pull request may close these issues.

None yet

3 participants