-
Notifications
You must be signed in to change notification settings - Fork 2
feat: added merge_round_robin
#2
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
base: master
Are you sure you want to change the base?
Conversation
| /// ``` | ||
| /// # futures::executor::block_on(async { | ||
| /// use futures::stream::{self, StreamExt}; | ||
| /// use streamies::Streamies as _; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// use streamies::Streamies as _; | |
| /// use streamtools::StreamTools as _; |
|
|
||
| // Check if we should be polling from the first stream. | ||
| // This means: | ||
| // - It's our turn to be polled AND the se |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete comment
| // - The stream isn't ended | ||
| if this.first_count < &mut this.first_nb_ele.get() { | ||
| if let Some(first) = this.first.as_mut().as_pin_mut() { | ||
| if let Some(item) = ready!(first.poll_next(cx)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this behaviour intentional - to wait for the first stream to yield, even if there are items available on the second stream?
My intuition would have been to fall back to the other stream if the first is pending, but I guess it depends on the use case.
Could possibly make this parameterisable or have a different variant which has the fallback behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RustyNova016 any thoughts on this? I think it'd be nice to have two variants: merge_round_robin and merge_round_robin_strict.
| use pin_project_lite::pin_project; | ||
|
|
||
| pin_project! { | ||
| /// Stream for the [`merge_round_robin`](crate::Streamies::merge_round_robin) method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Stream for the [`merge_round_robin`](crate::Streamies::merge_round_robin) method. | |
| /// Stream for the [`merge_round_robin`](crate::StreamTools::merge_round_robin) method. |
| "Couldn't convert `first_nb_ele` to `NonZeroUsize`. The value must no be 0", | ||
| ), | ||
| second_nb_ele: NonZeroUsize::new(second_nb_ele).expect( | ||
| "Couldn't convert `second_nb_ele` to `NonZeroUsize`. The value must no be 0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "Couldn't convert `first_nb_ele` to `NonZeroUsize`. The value must no be 0", | |
| ), | |
| second_nb_ele: NonZeroUsize::new(second_nb_ele).expect( | |
| "Couldn't convert `second_nb_ele` to `NonZeroUsize`. The value must no be 0", | |
| "Couldn't convert `first_nb_ele` to `NonZeroUsize`. The value must not be 0", | |
| ), | |
| second_nb_ele: NonZeroUsize::new(second_nb_ele).expect( | |
| "Couldn't convert `second_nb_ele` to `NonZeroUsize`. The value must not be 0", |
| /// | ||
| /// The resulting stream emits `nb_self` elements from the first stream, | ||
| /// then `nb_other` from the other. When one of the stream finishes, the | ||
| /// second is then used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a comment explaining that nb_self and nb_other must be non-zero or the method will panic?
IDK either 😅 I'll leave it to you. |
Added a function that allows merging two streams using a custom "round robin" policy.
This is an useful alternative to chain as the second stream doesn't wait for the first to finish, and both can be interweaved together
IDK what's the MSRV policy, but that would bump it to 1.82.0. I can bump it down to 1.63.0 but not sure if it's worth it
I'm also trying to upstream it to
futuresbut since the release cycle is sluggish, it can put put here for nowrust-lang/futures-rs#2930