You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an issue with publisher in the following code snippet (The snippet is stripped down to the essentials and does not implement an useful task).
I'm using Kotlin 1.2.10 and coroutines 0.21 with Java 8
fun withPublisher(context: CoroutineContext): Publisher<Unit> = publish(context) {
val sourceA = publish(context) { while (isActive) send(Unit) }
val sourceB = publish(context) { while (isActive) send(Unit) }
sourceA.openSubscription().use { channelA ->
sourceB.openSubscription().use { channelB ->
while (isActive) {
val index: Int = select {
channelA.onReceive { 0 }
channelB.onReceive { 1 }
}
when (index) {
0 -> {
channelB.receive()
send(Unit)
}
1 -> {
channelA.receive()
send(Unit)
}
}
}
}
}
}
fun main(args: Array<String>) = runBlocking<Unit> {
withPublisher(newSingleThreadContext("flow"))
.consumeEach { println("consume on thread ${Thread.currentThread().name}") }
}
The code hangs after the first consuming.
It works If I use Unconfined as CoroutineContext
I also tried the same with produce and Channels and it worked as well.
You find my experiments here.
I can see that in the second run the sourceB is suspended at the send()-method and the channelB.receive() is suspended as well.
The text was updated successfully, but these errors were encountered:
I have an issue with publisher in the following code snippet (The snippet is stripped down to the essentials and does not implement an useful task).
I'm using Kotlin 1.2.10 and coroutines 0.21 with Java 8
The code hangs after the first consuming.
It works If I use
Unconfined
asCoroutineContext
I also tried the same with
produce
and Channels and it worked as well.You find my experiments here.
I can see that in the second run the
sourceB
is suspended at thesend()
-method and thechannelB.receive()
is suspended as well.The text was updated successfully, but these errors were encountered: