Is it possible to ensure that a channel only ever ...
# coroutines
n
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
Do you want a
CompletableDeferred
instead?
n
Ooh, I did not realize there was a Kotlin version of this. I think that's more of what I'm after.
t
If you only need to wait for a single value, why not use a regular
suspend fun
?
a
If you're not producing and consuming from disjoint coroutines, yes, this is preferable ☝️