https://kotlinlang.org logo
Title
u

ursus

12/14/2021, 12:54 PM
How can I cancel a channel.send, that is waiting in receive buffer in unlimited?
z

Zach Klippenstein (he/him) [MOD]

12/14/2021, 4:08 PM
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

ursus

12/15/2021, 12:35 AM
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

Zach Klippenstein (he/him) [MOD]

12/15/2021, 7:14 PM
you could also create your own queue if you need other behaviors as well
u

ursus

12/15/2021, 7:38 PM
my queue how? custom channel subclass?
z

Zach Klippenstein (he/him) [MOD]

12/15/2021, 11:34 PM
no, just implement your own queue. could use channels internally but just as an implementation detail
u

ursus

12/16/2021, 12:49 AM
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