Does `delay` use <TimeSource.Monotonic>?
# coroutines
c
Does
delay
use TimeSource.Monotonic?
✅ 1
j
No. The dispatcher chooses how delay works.
d
If the dispatcher doesn't specify how delays work, by default,
System.nanoTime()
is used on the JVM: https://github.com/Kotlin/kotlinx.coroutines/blob/b11abdf01d4d5db85247ab365abc72efc7b95062/kotlinx-coroutines-core/jvm/src/DefaultExecutor.kt#L[…]20
h
The TestDispatcher used by
runTest
skips delays by „just“ increasing the virtual time.
c
Ah yeah that makes sense, thanks 🙇
e
If this question is testing related then you may want to get a
TimeSource
from the test dispatcher instead (and then pass that to your business logic):
h
And, you can convert the/a TimeSource to a kotlin.time.Clock too.
➕ 1