Created
July 23, 2018 08:13
-
-
Save Groostav/066c39cc5c33ce7c34d1c918e4705b29 to your computer and use it in GitHub Desktop.
producer-scope select-scope problem SSCCE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.lang.ClassCastException: kotlinx.coroutines.experimental.channels.ProducerCoroutine cannot be cast to kotlinx.coroutines.experimental.selects.SelectClause1 | |
at groostav.kotlinx.exec.CoroutineTests$when using select in producer to merge channels should operate normally$1$merged$1.doResume(CoroutineTests.kt:40) | |
at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:42) | |
at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(Dispatched.kt:162) | |
at kotlinx.coroutines.experimental.DispatchedContinuation.run(Dispatched.kt:26) | |
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) | |
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) | |
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) | |
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) | |
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test fun `when using select in producer to merge channels should operate normally`() = runBlocking<Unit> { | |
val sourceOne = produce { send(1); send(2); send(3) } | |
//inlining this var causes the test to pass | |
var s1: ReceiveChannel<Any>? = sourceOne | |
val merged = produce<Any>{ | |
while(isActive){ //removing this while causes the test to pass | |
val next = select<Any> { | |
s1?.onReceive { it -> it } | |
} | |
} | |
} | |
merged.receiveOrNull() | |
//does not reach here. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment