Add a way to request many permits on a mpsc::channel
#6174
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
M-sync
Module: tokio/sync
Is your feature request related to a problem? Please describe.
I'm making a library where I'm exposing an API that transforms a message into many payloads, then insert them into an
mpsc::channel
. Because I want to be able to return an error with the original message if the channel is full I need to use thePermit
API. However because I sendn
payload for1
message I need to be able to askn Permit
efficiently before doing the message transformation.Describe the solution you'd like
I noticed that the
Semaphore
API already has the possibility to askn
Permit and that the Permit API provided by thempsc::channel
is just a layer on top of it. So it shouldn't be too difficult to change the API. It could be something like that:Describe alternatives you've considered
There are two other possibilitie I considered:
Vec<Permit>
but this would allocate a new vec, so it is quite inneficient.Semaphore
with the same size next to my sender and synchronize it with my sender to track the number of given permits.Additional context
I'm willing to work on this feature if it is accepted.
The text was updated successfully, but these errors were encountered: