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

nwh

10/25/2020, 6:58 PM
Is it possible to ensure that a channel only ever receives a single value? For example, setting the capacity to 1, and immediately closing it such that any call to
offer
will throw an exception. I'm worried about the synchronization between the close call and the offer call. ie I need an atomic receiveAndClose (though I don't need it to be a channel)
a

Adam Powell

10/25/2020, 7:14 PM
Do you want a
CompletableDeferred
instead?
n

nwh

10/25/2020, 7:26 PM
Ooh, I did not realize there was a Kotlin version of this. I think that's more of what I'm after.
t

tseisel

10/25/2020, 8:06 PM
If you only need to wait for a single value, why not use a regular
suspend fun
?
a

Adam Powell

10/26/2020, 12:21 AM
If you're not producing and consuming from disjoint coroutines, yes, this is preferable ☝️
3 Views