File tree 6 files changed +15
-1
lines changed
6 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ package kotlinx.coroutines.flow
10
10
import kotlinx.coroutines.*
11
11
import kotlinx.coroutines.channels.*
12
12
import kotlinx.coroutines.flow.internal.*
13
+ import kotlinx.coroutines.internal.*
13
14
import kotlin.coroutines.*
14
15
import kotlin.jvm.*
15
16
@@ -204,8 +205,9 @@ private fun <T> CoroutineScope.launchSharing(
204
205
* * Delayed sharing strategies have a chance to immediately observe consecutive subscriptions.
205
206
* E.g. in the cases like `flow.shareIn(...); flow.take(1)` we want sharing strategy to see the initial subscription
206
207
* * Eager sharing does not start immediately, so the subscribers have actual chance to subscribe _prior_ to sharing.
208
+ * // TODO: kludge: native-mt doesn't support undispatched
207
209
*/
208
- val start = if (started == SharingStarted .Eagerly ) CoroutineStart .DEFAULT else CoroutineStart .UNDISPATCHED
210
+ val start = if (started == SharingStarted .Eagerly || isNativeMt ) CoroutineStart .DEFAULT else CoroutineStart .UNDISPATCHED
209
211
return launch(context, start = start) { // the single coroutine to rule the sharing
210
212
// Optimize common built-in started strategies
211
213
when {
Original file line number Diff line number Diff line change @@ -17,3 +17,5 @@ public expect open class SynchronizedObject() // marker abstract class
17
17
*/
18
18
@InternalCoroutinesApi
19
19
public expect inline fun <T > synchronized (lock : SynchronizedObject , block : () -> T ): T
20
+
21
+ internal expect val isNativeMt: Boolean
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package kotlinx.coroutines.flow
6
6
7
7
import kotlinx.coroutines.*
8
8
import kotlinx.coroutines.channels.*
9
+ import kotlinx.coroutines.internal.*
9
10
import kotlin.test.*
10
11
11
12
class ShareInTest : TestBase () {
@@ -213,6 +214,7 @@ class ShareInTest : TestBase() {
213
214
214
215
@Test
215
216
fun testShouldStart () = runTest {
217
+ if (isNativeMt) return @runTest
216
218
val flow = flow {
217
219
expect(2 )
218
220
emit(1 )
@@ -229,6 +231,7 @@ class ShareInTest : TestBase() {
229
231
230
232
@Test
231
233
fun testShouldStartScalar () = runTest {
234
+ if (isNativeMt) return @runTest
232
235
val j = Job ()
233
236
val shared = flowOf(239 ).stateIn(this + j, SharingStarted .Lazily , 42 )
234
237
assertEquals(42 , shared.first())
Original file line number Diff line number Diff line change @@ -18,3 +18,5 @@ public actual typealias SynchronizedObject = Any
18
18
@InternalCoroutinesApi
19
19
public actual inline fun <T > synchronized (lock : SynchronizedObject , block : () -> T ): T =
20
20
block()
21
+
22
+ internal actual val isNativeMt: Boolean = false
Original file line number Diff line number Diff line change @@ -18,3 +18,5 @@ public actual typealias SynchronizedObject = Any
18
18
@InternalCoroutinesApi
19
19
public actual inline fun <T > synchronized (lock : SynchronizedObject , block : () -> T ): T =
20
20
kotlin.synchronized(lock, block)
21
+
22
+ internal actual val isNativeMt: Boolean = false
Original file line number Diff line number Diff line change @@ -18,3 +18,6 @@ public actual typealias SynchronizedObject = kotlinx.atomicfu.locks.Synchronized
18
18
*/
19
19
@InternalCoroutinesApi
20
20
public actual inline fun <T > synchronized (lock : SynchronizedObject , block : () -> T ): T = lock.withLock2(block)
21
+
22
+ @OptIn(ExperimentalStdlibApi ::class )
23
+ internal actual val isNativeMt: Boolean = ! kotlin.native.isExperimentalMM()
You can’t perform that action at this time.
0 commit comments