File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
kotlinx-coroutines-core/nativeDarwin/src Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ private class DarwinMainDispatcher(
4646 val timer = Timer ()
4747 val timerBlock: TimerBlock = {
4848 timer.dispose()
49- continuation.resume (Unit )
49+ with ( continuation) { resumeUndispatched (Unit ) }
5050 }
5151 timer.start(timeMillis, timerBlock)
5252 continuation.disposeOnCancellation(timer)
Original file line number Diff line number Diff line change 11package kotlinx.coroutines.testing
22
33import kotlinx.coroutines.*
4+ import kotlinx.coroutines.channels.*
45import kotlin.test.*
56
67abstract class MainDispatcherTestBase : TestBase () {
@@ -151,6 +152,26 @@ abstract class MainDispatcherTestBase: TestBase() {
151152 }
152153 }
153154
155+ /* * Tests that [delay] runs the task inline instead of explicitly scheduling it
156+ * (which can be observed by the event loop's ordering). */
157+ @Test
158+ @NoJs @NoWasmWasi @NoWasmJs // This test does not work for environments with a single always-on event loop
159+ fun testUndispatchedAfterDelay () = runTestOrSkip {
160+ launch(Dispatchers .Main .immediate) {
161+ val channel = Channel <Unit >()
162+ expect(1 )
163+ launch {
164+ channel.receive()
165+ expect(3 )
166+ }
167+ delay(100 )
168+ checkIsMainThread()
169+ expect(2 )
170+ channel.send(Unit )
171+ finish(4 )
172+ }
173+ }
174+
154175 private suspend fun <R > withMainScope (block : suspend CoroutineScope .() -> R ): R {
155176 MainScope ().apply {
156177 return block().also { coroutineContext[Job ]!! .cancelAndJoin() }
You can’t perform that action at this time.
0 commit comments