-
Notifications
You must be signed in to change notification settings - Fork 30
Futures support #22
Comments
Yes, adding support for futures shouldn't be too difficult to do. |
Futures channels are not very ergonomic IMO and they are not mpmc. |
The first step here would be to implement But what should we do about That said, futures are already pretty flexible on their own so it's not hard to write a loop yourself that simply polls @tekjar What are the current pain points of futures channels? I don't have much experience with them, so I'm curious. |
And using references are difficult
Not sure if
This works in a loop but creating this future in a method is not trivial as you need to pass
|
FYI, the futures 0.2 RFC names |
@cramertj I'm planning to add futures support to Rather than simply implementing Therefore, the idea is to create entirely separate // Traditional channels without futures support.
struct Sender<T> { ... }
struct Receiver<T> { ... }
struct Iter<T> { ... }
struct IntoIter<T> { ... }
struct TryIter<T> { ... }
fn unbounded<T>() -> (Sender<T>, Receiver<T>) { ... }
fn bounded<T>(cap: usize) -> (Sender<T>, Receiver<T>) { ... }
// This macro works only with `Sender` and `Receiver` in the root
// module (the ones without futures support).
macro_rules! select { ... }
// Error types live here.
mod errors {
...
}
// Channels that work with futures.
mod async {
// Implements `Sink`.
struct Sender<T> { ... }
// Implements `Stream`.
struct Receiver<T> { ... }
fn unbounded<T>() -> (Sender<T>, Receiver<T>) { ... }
fn bounded<T>(cap: usize) -> (Sender<T>, Receiver<T>) { ... }
}
// Like `select!`, but it uses `yield` instead of `thread::park()`.
//
// This macro works only with `Sender` and `Receiver` in the `async` module.
macro_rules! async_select { ... } Do you have any thoughts on this split between traditional and asynchronous channels? Also, since you proposed creating a new |
@stjepang I'd love to see improvements to the |
I've put together a proof-of-concept futures-aware bounded mpsc channel which is living in this branch: https://github.com/danburkert/crossbeam-channel/tree/futures-channel. There's related discussion happening in rust-lang/futures-rs#800. I probably won't have a ton of time to dedicate to getting this over the finish-line, either in terms of merging into futures-rs or into crossbeam-channel (I don't yet know which is more appropriate), so if anyone is interested in pushing on it, please go ahead. |
@danburkert would love to extend your Poc to support mpmc, just not sure how to go about it. If you could point me to the relevant resources to read up on, I should be able to have a working Poc by tomorrow. |
Hey @seunlanlege, that sounds great! I've pushed a commit which expands the implementation comments/documentation so hopefully it is easier to see how the channel mechanisms work. I'd suggest looking over that with a special focus on As far as extending to an mpmc channel, I think you'll have to replace the |
WIP pr here #38 |
Issuers are less efficient than we'd like since we now need to alternate between turning the core and trying to receive new jobs. This will be fixed once the crossbeam-channel crate is futures-aware: crossbeam-rs/crossbeam-channel#22
As mentioned in this comment, I think it'd probably make more sense to simply build a new crate with futures support from scratch. There are probably no real blockers, I just need to dedicate time and effort to it. |
Hi. Thanks a lot for this crate. Are there any plans of adding
futures
support?The text was updated successfully, but these errors were encountered: