smol-rs / futures-lite

Futures, streams, and async I/O combinators.
Apache License 2.0
449 stars 26 forks source link

Add the once_future() combinator #59

Closed notgull closed 1 year ago

notgull commented 2 years ago

Resolves #52

taiki-e commented 2 years ago

Why does this add both freestanding function and method?

notgull commented 2 years ago

I assumed that was the status quo for futures_lite, like how zip and or are methods.

taiki-e commented 2 years ago

I guess it is only happening with methods that take two or more futures/streams. (e.g., catch_unwind is trait method only) There has been discussion in the past in futures that freestanding functions are preferred for such methods: https://github.com/rust-lang/futures-rs/issues/1215

taiki-e commented 2 years ago

It seems you have removed the trait method, but I have the impression that into_ is a prefix that is often used in the method (e.g., String::into_bytes, {BufReader,BufWriter}::into_inner).

notgull commented 2 years ago

You're right. How would you feel about just the name stream()?

taiki-e commented 2 years ago

Maybe stream::from_future?

That said, I have no strong opinion on this as I tend to prefer the futures's APIs that take the future as an argument (i.e., I think stream::once is the ideal name here).

taiki-e commented 2 years ago

@smol-rs/admins: Any thoughts on the API here?

zeenix commented 2 years ago

@smol-rs/admins: Any thoughts on the API here?

I agree with you about the naming. stream::once seems better to me as well.

notgull commented 2 years ago

I like the idea of stream::once, however, that method already exits and just yields a single value without being asynchronous. I renamed this type to stream::once_future().

fogti commented 2 years ago

So this does just the same as https://docs.rs/futures-util/0.3.24/futures_util/future/struct.IntoStream.html ? / https://docs.rs/futures-util/0.3.24/futures_util/stream/struct.Once.html

notgull commented 2 years ago

Yes, the idea is to give the user the ability to turn a Future into a Stream.

fogti commented 1 year ago

this should be squash-merged.