Skip to content

Commit 9169d09

Browse files
authored
Rollback #2972, but leave a compatibility option with 1.6.0 (#3131)
The approach from 1.6.0 has proven itself as unstable and multiple hard-to-understand bugs have been reported: * JavaFx timer doesn't really work outside the main thread * The frequent initialization pattern "runBlocking { doSomethingThatMayCallDelay() }" used on the main thread during startup now silently deadlocks * The latter issue was reported both by Android and internal JB Compose users * The provided workaround with system property completely switches off the desired behaviour that e.g. Compose may rely on, potentially introducing new sources of invalid behaviour The original benefits does not outweigh these pitfalls, so the decision is to revert this changes in the minor release Fixes #3113 Fixes #3106
1 parent ce02a3f commit 9169d09

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

kotlinx-coroutines-core/jvm/src/DefaultExecutor.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlinx.coroutines.internal.*
88
import java.util.concurrent.*
99
import kotlin.coroutines.*
1010

11-
private val defaultMainDelayOptIn = systemProp("kotlinx.coroutines.main.delay", true)
11+
private val defaultMainDelayOptIn = systemProp("kotlinx.coroutines.main.delay", false)
1212

1313
internal actual val DefaultDelay: Delay = initializeDefaultDelay()
1414

ui/kotlinx-coroutines-android/test/HandlerDispatcherTest.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,19 @@ class HandlerDispatcherTest : TestBase() {
163163
}
164164

165165
@Test
166-
fun testDelayIsDelegatedToMain() = runTest {
166+
fun testDelayIsNotDelegatedToMain() = runTest {
167167
val mainLooper = shadowOf(Looper.getMainLooper())
168168
mainLooper.pause()
169169
val mainMessageQueue = shadowOf(Looper.getMainLooper().queue)
170170
assertNull(mainMessageQueue.head)
171171
val job = launch(Dispatchers.Default, start = CoroutineStart.UNDISPATCHED) {
172172
expect(1)
173-
delay(10_000_000)
174-
expect(3)
173+
delay(Long.MAX_VALUE)
174+
expectUnreached()
175175
}
176176
expect(2)
177-
assertNotNull(mainMessageQueue.head)
178-
mainLooper.runOneTask()
179-
job.join()
180-
finish(4)
177+
assertNull(mainMessageQueue.head)
178+
job.cancelAndJoin()
179+
finish(3)
181180
}
182181
}

0 commit comments

Comments
 (0)