You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm in a case where I need to serialize, then send multiple values across an mpsc::channel which is managed by another function.
The only solution I found is with the Permit API is to ask n permits and then give a Vec<Permit> to my function that handles the channel but it allocates a Vec so it is quite bad...
Otherwise my solution is to have a raw Semaphore field next to my channel to track sending permission.
Overall, would it be possible to have a reserve_many fn added to the mpsc::channel struct ?
impl<T>ManyPermit<'_,T>{pubfnsend(&mutself,value:T){ifself.n > 0{self.chan.send(value);self.n -= 1;}}}impl<T>DropforManyPermit<'_,T>{fndrop(&mutself){use chan::Semaphore;let semaphore = self.chan.semaphore();// Add the remaining permits back to the semaphore
semaphore.add_permits(self.nasusize);// If this is the last sender for this channel, wake the receiver so// that it can be notified that the channel is closed.if semaphore.is_closed() && semaphore.is_idle(){self.chan.wake_rx();}}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm in a case where I need to serialize, then send multiple values across an
mpsc::channel
which is managed by another function.The only solution I found is with the
Permit
API is to ask n permits and then give aVec<Permit>
to my function that handles the channel but it allocates a Vec so it is quite bad...Otherwise my solution is to have a raw
Semaphore
field next to my channel to track sending permission.Overall, would it be possible to have a
reserve_many
fn added to thempsc::channel
struct ?Something like this :
Beta Was this translation helpful? Give feedback.
All reactions