brett.wooldridge
06/11/2019, 6:16 AMlouiscad
06/11/2019, 6:18 AMsuspendCancellableCoroutine
like with any single execution cancellable/unregisterable callback.brett.wooldridge
06/11/2019, 6:20 AMsuspendCancellableCoroutine
and the ability to suspend for nanoseconds (or microseconds) is not clear to me.louiscad
06/11/2019, 6:21 AMdelayNanos
function with it and an API from the platform that allows delaying with nanoseconds parameter.brett.wooldridge
06/11/2019, 6:24 AMparkNanos()
is a blocking call, but delay()
is a suspending call, so how is the delay itself achieved without invoking an underlying blocking platform call?octylFractal
06/11/2019, 6:33 AMbrett.wooldridge
06/11/2019, 6:36 AMdelay(20ms)
may not actually resume until tens, hundreds, or even thousands of milliseconds later)elizarov
06/11/2019, 6:52 AMoctylFractal
06/11/2019, 7:02 AMdelay()
is a suspending call", it depends on the underlying implementation, but typically, the thread pool will do the blocking. the difference being, the thread pool can do other work that is ready while waiting for your task to finish delaying, since it knows of all the tasks it needs to be executing.
essentially, when you call delay()
, Kotlin schedules a task after the delay that calls back into your method to continue execution. see the generated bytecode, it basically is a switch statement to which part of the method it should be executing, and suspending will just tell it to call the next part.brett.wooldridge
06/11/2019, 7:11 AMCoroutineScheduler
already uses parkNanos()
and does all internal math based on nanoseconds…would be nice to have it exposed. When is Duration
expected to be added to stdlib? 1.4?