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

Feature: Stream impl for Dequeue #3

Open
khionu opened this issue Oct 31, 2024 · 4 comments
Open

Feature: Stream impl for Dequeue #3

khionu opened this issue Oct 31, 2024 · 4 comments

Comments

@khionu
Copy link

khionu commented Oct 31, 2024

Implementing Iterator/Stream gives a lot of convenience, it would expand a lot of ergonomics to implement Stream on Dequeue.

@faiface
Copy link
Owner

faiface commented Nov 15, 2024

@khionu Thanks! I now implemented a Dequeue::into_stream1 method that transforms a Dequeue<T, ()> (so without a continuation) into a futures::Stream of T.

An implementation for a Dequeue with a continuation would be possible, but I'm not sure about the design yet. I see two possible designs:

  1. Have dequeue.into_stream(|recv_cont: Recv<S>| ...) pass the continuation via the provided Recv. It needs to be provided into a closure to maintain deadlock prevention.
  2. Make dequeue.into_stream() produce a Stream of a sum type of either a T or an S. Unfortunately, there is no standard "either" type in Rust, so it would have to be a custom sum type.

I'm leaning towards the first option, what do you think?

@khionu
Copy link
Author

khionu commented Nov 17, 2024

I'm not sure how the first would function without reducing ergonomics? It wouldn't be able to be consumed within the iterator chain or loop blocks because you wouldn't be able to enforce a break of the loop.

A custom Either is a very common approach, and given the nature of Par I think it would be very appropriate for it to have one.

@faiface
Copy link
Owner

faiface commented Nov 18, 2024

That's true, thanks!

The first approach introduces a scope separation where it's not appropriate.

I'll implement the second approach.

@faiface
Copy link
Owner

faiface commented Nov 19, 2024

Implemented: https://docs.rs/par/0.3.9/par/queue/struct.Dequeue.html#method.into_stream

@khionu Let me know if anything is missing, or if this issue is now resolved!

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

2 participants