Clament John
11/27/2021, 10:09 AMlouiscad
11/28/2021, 12:25 PMTwoClocks
11/28/2021, 8:05 PMTwoClocks
11/28/2021, 8:06 PMTwoClocks
11/28/2021, 8:07 PMsuspend {
println("one")
delay(1000)
println("two")
}
And look at the resulting java code the kotlin compiler outputs it sorta looks like :
void suspendFn(int version) {
switch(version) {
case 1:
println("one");
setDelay(1000);
break;
case 2:
println("two");
break;
}
}
TwoClocks
11/28/2021, 8:12 PMresume
the compiler turns in into a call to suspendFn(2)
TwoClocks
11/28/2021, 8:15 PMtask
. In theory, you can suspend them at any point, just like a thread can, unlike stackless which run until a suspend point is hit.TwoClocks
11/28/2021, 8:19 PMTwoClocks
11/28/2021, 8:19 PMsuspend
and async
it's stackless.TwoClocks
11/28/2021, 8:22 PMTwoClocks
11/28/2021, 8:23 PMClament John
11/29/2021, 5:49 PMTwoClocks
11/29/2021, 6:42 PMClament John
11/29/2021, 6:51 PMErik
11/29/2021, 9:16 PMsuspend
keyword, but not the async
and await
keywords? That's the brilliance of Kotlin coroutines, IMO!Erik
11/29/2021, 9:21 PMErik
11/29/2021, 9:23 PMTwoClocks
11/29/2021, 10:27 PMTwoClocks
11/29/2021, 10:28 PMgenerateSqeuence
in the stdlib uses coroutines, but has not dependency on kotlinx-coroutines.TwoClocks
11/29/2021, 10:30 PM