altavir
03/20/2025, 10:05 AMDmitry Khalanskiy [JB]
03/20/2025, 10:11 AMwhile (true)
at some point, because no one but you knows whether there are tasks left for your custom dispatcher to process. You can abstract the lower-level details away, though, by reusing the event loop from runBlocking
. We do that in kotlinx-coroutines-test
(https://github.com/Kotlin/kotlinx.coroutines/blob/465e29d325841244f3a1aac2e13073bc965f9736/kotlinx-coroutines-test/common/src/TestBuilders.kt#L[…]61), though I suspect we'll change that eventually.altavir
03/20/2025, 10:15 AMDmitry Khalanskiy [JB]
03/20/2025, 10:20 AMaltavir
03/20/2025, 10:23 AMdelay
, say for 200 milliseconds, then I need for it to record time mark in virtual time scheduler and if all other timelines are right it should immediately continue without waiting for real 200 milliseconds. I mean that I need to notify scheduler that time has passed.altavir
03/20/2025, 10:23 AMaltavir
03/20/2025, 10:25 AMDmitry Khalanskiy [JB]
03/20/2025, 10:26 AMkotlinx-coroutines-test
, except that we never wait for any real time. I think https://github.com/Kotlin/kotlinx.coroutines/blob/465e29d325841244f3a1aac2e13073bc965f9736/kotlinx-coroutines-test/common/src/TestBuilders.kt#L[…]36 together with https://github.com/Kotlin/kotlinx.coroutines/blob/465e29d325841244f3a1aac2e13073bc965f9736/kotlinx-coroutines-test/common/src/TestDispatcher.kt and https://github.com/Kotlin/kotlinx.coroutines/blob/465e29d325841244f3a1aac2e13073bc[…]36/kotlinx-coroutines-test/common/src/TestCoroutineScheduler.kt should give the full picture.altavir
03/20/2025, 10:34 AMDmitry Khalanskiy [JB]
03/20/2025, 10:37 AMLockSupport.parkNanos
, call unpark
. If it's kotlinx.coroutines.delay
, replace that with select { }
with the timeout clause and the clause for obtaining the "time to wake up" message channel. If it's Thread.sleep
, your friend is Thread.interrupt
.altavir
03/20/2025, 10:38 AM