<@U223RM5CH> Can you, please, add a self-contained...
# coroutines
e
@dragas Can you, please, add a self-contained example that crashes?
d
Copy code
fun main(args: Array<String>) = runBlocking()
{
    val actor = getIntActor()
    delay(1000)
}

fun getIntActor() = actor<Int>(CommonPool)
{
    consumeEach(::consumeInt)
}

fun consumeInt(it : Int)
{
    println(it)
}
e
Works for me (with
kotlinx.coroutines
version 0.18)
What’s your setup where it does not work?
d
I am also using
kotlinx.coroutines 0.18
and
kotlin 1.1.4-2
in a multi module gradle project, And it doesn't work anywhere, really. Be it the example I provided, or deep in the project. This is the only place I tried using actors at. https://pastebin.com/pgMgydRK
for(response in channel)
doesn't throw that and seems to work as intended.
Using
consumeEach
on regular channels throws that too, but with
Exception in thread "kotlinx.coroutines.DefaultExecutor" Exception in thread "main" java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.Boolean
Copy code
fun main(args: Array<String>) = runBlocking()
{
    val channel = Channel<Int>(Channel.UNLIMITED)

    channel.consumeEach { println(it) }

    delay(1000)
}

fun consumeInt(it: Int)
{
    println(it)
}
e
Can you share your project setup?
(via github, for example)
e
I’m lost at how to reproduce it. Here is what I’m doing: * git clone https://github.com/Dragas/bIRC.git -b async-dev * Opened this project in IDEA (2017.2.3, Kotlin plugin 1.1.4-3) * Imported Gradle project, configured JDK to 1.8.0_131 * Navigated to async/src/test * Created file named
T.kt
with the code above of your, pressed Alt+ENTER many times to add all the imports * Now when I run it it just works, does not crash
Here is the full code I’m running with all the imports (in
T.kt
):
Copy code
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.channels.actor
import kotlinx.coroutines.experimental.channels.consumeEach
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.runBlocking

fun main(args: Array<String>) = runBlocking()
{
    val actor = getIntActor()
    delay(1000)
}

fun getIntActor() = actor<Int>(CommonPool)
{
    consumeEach(::consumeInt)
}

fun consumeInt(it : Int)
{
    println(it)
}
You should try clean/rebuild project. Maybe something broken in some caches. You can try “Invalidate caches / Restart” action
d
Yep, that helped. Sorry to bother you for it 😞