File tree 2 files changed +18
-2
lines changed
reactive/kotlinx-coroutines-reactive
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package kotlinx.coroutines.reactive
6
6
import kotlinx.atomicfu.*
7
7
import kotlinx.coroutines.*
8
8
import kotlinx.coroutines.channels.*
9
+ import kotlinx.coroutines.intrinsics.*
9
10
import kotlinx.coroutines.selects.*
10
11
import kotlinx.coroutines.sync.*
11
12
import org.reactivestreams.*
@@ -104,10 +105,22 @@ public class PublisherCoroutine<in T>(
104
105
// registerSelectSend
105
106
@Suppress(" PARAMETER_NAME_CHANGED_ON_OVERRIDE" )
106
107
override fun <R > registerSelectClause2 (select : SelectInstance <R >, element : T , block : suspend (SendChannel <T >) -> R ) {
107
- mutex.onLock.registerSelectClause2(select, null ) {
108
+ val clause = suspend {
108
109
doLockedNext(element)?.let { throw it }
109
110
block(this )
110
111
}
112
+
113
+ // TODO discuss it
114
+ launch(start = CoroutineStart .UNDISPATCHED ) {
115
+ mutex.lock()
116
+ // Already selected -- bail out
117
+ if (! select.trySelect()) {
118
+ mutex.unlock()
119
+ return @launch
120
+ }
121
+
122
+ clause.startCoroutineCancellable(select.completion)
123
+ }
111
124
}
112
125
113
126
/*
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import kotlinx.coroutines.*
8
8
import kotlinx.coroutines.CancellationException
9
9
import kotlinx.coroutines.channels.*
10
10
import kotlinx.coroutines.flow.*
11
+ import kotlinx.coroutines.sync.*
11
12
import org.junit.Test
12
13
import org.reactivestreams.*
13
14
import java.util.concurrent.*
@@ -308,13 +309,15 @@ class PublishTest : TestBase() {
308
309
}
309
310
310
311
expect(1 )
312
+ val collectorLatch = Mutex (true )
311
313
val job = launch {
312
314
published.asFlow().buffer(0 ).collect {
313
315
expect(4 )
316
+ collectorLatch.unlock()
314
317
hang { expect(6 ) }
315
318
}
316
319
}
317
- yield ()
320
+ collectorLatch.lock ()
318
321
expect(5 )
319
322
job.cancelAndJoin()
320
323
latch.await()
You can’t perform that action at this time.
0 commit comments