-
Notifications
You must be signed in to change notification settings - Fork 341
Feature request: Add unbounded channels #691
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
Comments
@dignifiedquire can you perhaps share why having e.g. use async_std::sync::channel;
let (sender, receiver) = channel(usize::max_value()); I haven't been closely involved with the channel implementation. But my understanding is that making a queue effectively unbounded versus guaranteed to be unbounded requires very different implementations. Which in turn require time to build and maintain. Off the cuff the only thing I can really come up with for completely unbounded channels is that the signature for task::spawn(async {
dbg!(receiver.recv().await);
});
sender.send(b"some data"); // notice: no .await needed here. This seems possibly useful when trying to communicate from sync -> async code. But given we already have So in conclusion, this is not to say there aren't any valid uses for unbounded channels. But what I think would be most helpful here is a clear motivating use case that is clearly best implemented through unbounded channels. |
I think I could probably work with simply setting a very large limit. My only concern with this would be, does the implementation do any preallocation based on this? because if so that would make this use very risky, as I definitely do not want to pay the cost of allocating billions of entries, when in reality only a 100 or so are ever in there. |
@dignifiedquire you're entirely right; we do preallocate and that indeed fails at higher numbers. |
I have a use case where each Sender gets 1 guaranteed slot, just like the mpsc channel in futures but without their shared buffer. I use each Sender only once as a way to propagate an error message to some supervisor process, and for that they can send synchronously. Since all Senders are cloneable, the channel is theoretically unbounded, but its actual size is determined by the application at runtime as Senders are created and dropped. I think it is better to use a linked list in this case. |
Closed by #827 |
I regularly use unbounded channels, even though they might not be ideal from a perf perspective they make it easy to not have to worry about the exact enforced boundaries, and suddenly blocking the whole operation, just because there is no/a slow consumer.
The text was updated successfully, but these errors were encountered: