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

mingkangpan

11/29/2018, 11:08 AM
I have a question: if I am launching a coroutines, and want to return and cancel it, if some if condition doesn't fullfil how do I do? like this?
Copy code
launch {
   val isYes = channel.receive
   if(!isYes) {
       coroutineContext.cancel()
       return@launch
   }
   
   //process further logic
}
d

Daniel Tam

11/29/2018, 11:28 AM
if you only want to stop the coroutine executing inside your
launch
block, simply
return@launch
no need to cancel the context
4 Views