I have a question: if I am launching a coroutines,...
# coroutines
m
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
if you only want to stop the coroutine executing inside your
launch
block, simply
return@launch
no need to cancel the context