efemoney
02/09/2021, 11:01 AMclose
a channel if I only want to receive
a single value from it? Something like this inside some suspend function
val whatIWant = myChannel.receive()
myChannel.close()
return whatIWant
// VS
return mychannel.receive()
Vivek Sharma
02/09/2021, 11:09 AMmarstran
02/09/2021, 11:14 AMChannel
is the correct approach if you only want to receive a single value?efemoney
02/09/2021, 11:17 AMVivek Sharma
02/09/2021, 11:17 AMefemoney
02/09/2021, 11:19 AMmyChannel.receiveAsFlow().first()
// AND
myChannel.receive()
Vivek Sharma
02/09/2021, 11:24 AMefemoney
02/09/2021, 11:25 AMVivek Sharma
02/09/2021, 11:25 AMmarstran
02/09/2021, 11:51 AMsuspendCancellableCoroutine
to convert the callback-function to a normal suspend function.callbackFlow
instead.efemoney
02/09/2021, 11:58 AM