-
Notifications
You must be signed in to change notification settings - Fork 634
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
Support infinite streams #1857
Comments
|
I can't help but feel this reasoning is similar to what lead to Is there a concrete benefit with this, over specializing over an enum like |
I don't think this is quite the same situation as |
I am curious about the impact of the |
Relevant previous discussion: #1059 |
I'm happy to leave this open for discussion, but my personal temperature on this is that we don't need native support for streams with a separate final output type from their normal yielded type. The benefits gained from modeling these kinds of streams differently aren't worth the costs, IMO. @sfackler previously made an effort to develop these stream types in a separate crate, and I believe came to the same conclusion. |
@cramertj It isn't clear to me what your opinion on dropping the mandatory Reviewing the code I've written so far which uses futures, I currently don't have a single use case for finite streams. They are always either errors or panics (through e.g. |
I have many usecases for finite streams. Consider the |
Similarly, |
Yeah. I'd hope to be able to mimic the current API using extension traits, similarly to how we have
That is one of the sticking points mentioned above. There might be a way to avoid having multiple combinator implementations, but I'm not sure since I haven't put in the work to try it. Otherwise different functions with distinct names would be an option, one conditional on It is worth noting that with the advent if async/await I'd expect most combinators to see much less use in favor of writing them out like imperative code. At least that's consistent with my experience with async/await so far. I don't use async {
while let Some(result) = stream.next().await {
/*. */
}
panic!("stream ended");
} My more general point was that, apart from |
I find the way channels terminate when the senders have all been dropped to be useful for gracefully shutting down message-driven spawned tasks, at least. |
It's kind of funny that I didn't even know that the contract for channels worked like this because it was put behind a |
Yeah, that use-case would still work just fine if it was an infinite stream that had a sentinel value like In other words, a problem with the current API is that the "separate final output type" is required to be The dwindling importance of combinators is a valid point in some respects, but if you specifically need to transform a stream to pass it on to another API, combinators remain the only option at least until we get something like async generators. There's also no easy way to supplant e.g. |
|
I've had the opposite experience, the majority of my |
Hm. Do these tend to resolve to |
They're mostly per-client |
This is an issue opened to consider adding support for infinite streams as a first-class abstraction.
Infinite streams are streams which do not terminate, so they yield values of
T
directly instead ofOption<T>
. This is useful for things which conceptually never ends, likeInterval
s, channels, or lazy settings updates. The fact that we currently have a panickingselect_next_some
speaks to me that there might be space for this.Infinite streams would look something like this:
Or in a perfect world, consider making the existing
Stream
not resolve with anOption<T>
and make terminating streams a specialization on this. Similarly to howResult<T, E>
was removed fromFuture
. This in my mind would eventually suit streams as a language item better, like:Which could produce an implementation of
Stream<Item = YieldOrReturn<u32, u32>>
. Which forStream<Item=YieldOrReturn<u32, ()>>
would have the same semantics asStream<Item = Option<u32>>
.An infinite stream with could look something like:
And would produce an implementation of
Stream<Item = u32>
.One sticking point I'm not sure about is if combinators could be implemented once instead of once per stream variant (terminating vs infinite).
CC: #1765
The text was updated successfully, but these errors were encountered: