Hi, I launch a coroutine with `while(true) { ... d...
# coroutines
m
Hi, I launch a coroutine with
while(true) { ... delay(3000) }
code in it. Is is possible to somehow trigger skip of the delay (waiting 3s) and run the while loop body immediately?
d
Where do you want to trigger the skip from?
By skip, I assume you mean to interrupt the coroutine suspended in the
delay
function.
select
might help you.
e
Yes. Create a channel, and the instead of
delay(3000)
, do:
Copy code
select { 
    channel.onReceive { /* skipped */ }
    onTimeout(3000) { /* waited */ }
}
1
👍🏼 1