File tree 2 files changed +20
-2
lines changed
kotlinx-coroutines-core/jvm/src
ui/kotlinx-coroutines-android/test
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ import kotlinx.coroutines.internal.*
8
8
import java.util.concurrent.*
9
9
import kotlin.coroutines.*
10
10
11
- internal actual val DefaultDelay : Delay = initializeDefaultDelay()
12
-
13
11
private val defaultMainDelayOptIn = systemProp(" kotlinx.coroutines.main.delay" , true )
14
12
13
+ internal actual val DefaultDelay : Delay = initializeDefaultDelay()
14
+
15
15
private fun initializeDefaultDelay (): Delay {
16
16
// Opt-out flag
17
17
if (! defaultMainDelayOptIn) return DefaultExecutor
Original file line number Diff line number Diff line change @@ -161,4 +161,22 @@ class HandlerDispatcherTest : TestBase() {
161
161
assertEquals(" Dispatchers.Main" , Dispatchers .Main .toString())
162
162
assertEquals(" Dispatchers.Main.immediate" , Dispatchers .Main .immediate.toString())
163
163
}
164
+
165
+ @Test
166
+ fun testDelayIsDelegatedToMain () = runTest {
167
+ val mainLooper = shadowOf(Looper .getMainLooper())
168
+ mainLooper.pause()
169
+ val mainMessageQueue = shadowOf(Looper .getMainLooper().queue)
170
+ assertNull(mainMessageQueue.head)
171
+ val job = launch(Dispatchers .Default , start = CoroutineStart .UNDISPATCHED ) {
172
+ expect(1 )
173
+ delay(10_000_000 )
174
+ expect(3 )
175
+ }
176
+ expect(2 )
177
+ assertNotNull(mainMessageQueue.head)
178
+ mainLooper.runOneTask()
179
+ job.join()
180
+ finish(4 )
181
+ }
164
182
}
You can’t perform that action at this time.
0 commit comments