Commit ba87db3 1 parent cb19b9a commit ba87db3 Copy full SHA for ba87db3
File tree 2 files changed +11
-1
lines changed
kotlinx-coroutines-core/nativeDarwin
2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ private class DarwinMainDispatcher(
28
28
29
29
init { freeze() }
30
30
31
- override fun isDispatchNeeded (context : CoroutineContext ): Boolean = ! invokeImmediately || isMainThread()
31
+ override fun isDispatchNeeded (context : CoroutineContext ): Boolean = ! ( invokeImmediately && isMainThread() )
32
32
33
33
override fun dispatch (context : CoroutineContext , block : Runnable ) {
34
34
dispatch_async(dispatch_get_main_queue()) {
Original file line number Diff line number Diff line change 4
4
5
5
package kotlinx.coroutines
6
6
7
+ import kotlin.coroutines.*
7
8
import kotlin.test.*
8
9
9
10
class MainDispatcherTest : TestBase () {
10
11
private val testThread = currentThread()
11
12
13
+ @Test
14
+ fun testDispatchNecessityCheckWithMainImmediateDispatcher () {
15
+ runTest {
16
+ val immediate = Dispatchers .Main .immediate
17
+ val needsDispatch = testThread != mainThread
18
+ assertEquals(needsDispatch, immediate.isDispatchNeeded(EmptyCoroutineContext ))
19
+ }
20
+ }
21
+
12
22
@Test
13
23
fun testWithContext () {
14
24
if (testThread == mainThread) return // skip if already on the main thread
You can’t perform that action at this time.
0 commit comments