Add StreamExt::wait_until
combinator
#2542
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
stream.wait_until(fut)
combinator lets the stream to wait until the future resovles. The stream start taking elements if the future resolves to true, otherwise the stream fuses if it resolve to false.It is useful for initialization purpose. For example, the stream has to wait for user configuration to be ready to start producing values, and fuse the stream if the configuration is not correct. The code below illustrates the idea.
A practical example is in my par-stream crate. To broadcast the messages from a stream, it creates a builder to user. The user registers receivers using the builder. The receivers should wait until the builder is finished or dropped. It ensures that every receiver can read the first value from stream.