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(
46
46
val timer = Timer ()
47
47
val timerBlock: TimerBlock = {
48
48
timer.dispose()
49
- continuation.resume (Unit )
49
+ with ( continuation) { resumeUndispatched (Unit ) }
50
50
}
51
51
timer.start(timeMillis, timerBlock)
52
52
continuation.disposeOnCancellation(timer)
Original file line number Diff line number Diff line change 1
1
package kotlinx.coroutines.testing
2
2
3
3
import kotlinx.coroutines.*
4
+ import kotlinx.coroutines.channels.*
4
5
import kotlin.test.*
5
6
6
7
abstract class MainDispatcherTestBase : TestBase () {
@@ -151,6 +152,26 @@ abstract class MainDispatcherTestBase: TestBase() {
151
152
}
152
153
}
153
154
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
+
154
175
private suspend fun <R > withMainScope (block : suspend CoroutineScope .() -> R ): R {
155
176
MainScope ().apply {
156
177
return block().also { coroutineContext[Job ]!! .cancelAndJoin() }
You can’t perform that action at this time.
0 commit comments