How can I cancel a channel.send, that is waiting i...
# coroutines
u
How can I cancel a channel.send, that is waiting in receive buffer in unlimited?
z
You can't remove something from a channel once it's been sent.
You could use an unbuffered channel to force all sends to suspend on backpressure - then you could cancel sends by cancelling the coroutine performing the send (I think). Channel sends are fair, so this would still act like a queue – 5 coroutines call and suspending on send will be sent+resumed in order.
u
would you do that if you were to create a sort of a downloader queue? to rely on the backpressure, keeping the Jobs in a map, and cancel them when user decides to? would work but sounds iffy
z
you could also create your own queue if you need other behaviors as well
u
my queue how? custom channel subclass?
z
no, just implement your own queue. could use channels internally but just as an implementation detail
u
but then the queue needs to be shared state, with sychronization etc which I wanted to avoid.. thread that blocks on BlockingQueue.take almost feels better now