Open
Description
After the last receiver is dropped, all the items in the channel are effectively abandoned and can never be accessed. In this scenario, I think it's appropriate to drain the channel and drop all the items. One use case where this is relevant is a dispatch mechanism that uses oneshot channels:
let (req_s, req_r) = bounded(10);
// dispatch
for i in 0.. {
let (s, r) = oneshot();
req_s.send((i, s)).await.unwrap();
let res = r.recv().await.unwrap();
}
// worker
while let Ok((i, s)) = req_r.recv().await {
s.send(do_work(i));
}
Here, if worker
terminates while there are still requests in the channel, dispatch
can end up waiting for the response forever. This can be addressed with timeouts, but I think automatically draining the channel is a better solution.
Metadata
Metadata
Assignees
Labels
No labels