https://kotlinlang.org logo
#coroutines
Title
# coroutines
l

louiscad

10/01/2018, 3:18 PM
Hi, is there a way to cancel/close a
ReceiveChannel
without clearing its buffer? I'd like to stop an underlying items generation, and get what was processed so far as a list. I used
cancel()
in the past, but it seems it now clears the buffer, and I'm looking for an alternative.
e

elizarov

10/01/2018, 3:23 PM
cancel
- clears. It is used by receiver to indicate that it does not plan to receive anything anymore.
close
- dose not clear. It is used by sender to indicate that it does not plan to send anymore.
l

louiscad

10/02/2018, 7:07 AM
It makes it a bit hard to receive elements only for a time duration, but I could solve my problem with an
async
block calling
toList()
, then cancelling before awaiting the result of the
async
block. Thank you!