-
Notifications
You must be signed in to change notification settings - Fork 471
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
Add Receiver::new_sender
to channels
#750
base: master
Are you sure you want to change the base?
Conversation
Receiver::new_sender
to channels
todo!() wasn't stable back in 1.36.0. I feel like unreachable!() is more appropriate anyway, as these code branches are unreachable until we implement the corresponding public function `bounded`.
hey, this api is interesting to me as well.
However, I didn't particularly like this submodule arrangement... How about making |
ping @oowekyala @taiki-e regarding my api idea: #750 (comment) |
This change gives some
channel::Receiver
s the ability to spawn new senders at will.Currently, Receivers are disconnected as soon as the Sender count reaches zero, as new Senders can only be created by cloning an existing one. Disconnected receivers do not block on
recv
and such, instead they just fail immediately.This didn't quite fit my use case, where I need to have the ability to create new Senders when I want to, and also get the non-blocking behavior if there is no Sender alive. With the current API, I have to keep a prototype Sender which is always alive and which I can clone whenever I want. The problem is that since the prototype is always alive, the channel never gets disconnected. That means calls to
recv
stay blocking, even when we know that no message will ever be sent through the Sender prototype, because its only purpose is to produce new Senders.This change creates a new Receiver type that supports creating new Sender instances. That means, I don't need to keep a Sender prototype anymore, so my Receiver is non-blocking when I know there is no real Sender alive. But even after the channel was disconnected, you can "reconnect" it by spawning new senders.
Obviously this method cannot appear in the API of channel flavours like
tick
ornever
, since the point of those is to expose only a receiver. This means, we need two different types forReceiver
. I put that new API in a separate submodule so that it's easy to import and document. That submodule only supports creating unbounded channels for now, as that was my use case. If you're interested we may be able to add support for bounded and zero channels, but there is AFAIK no risk in keeping an incomplete API here.Please let me know if there is anything you need from me to get this merged faster, be it documentation, tests, etc.
Cheers :)