https://kotlinlang.org logo
Title
c

cah

04/21/2022, 3:38 PM
Why does this not work?
fun CoroutineScope.launchIO(block: suspend CoroutineScope.() -> Unit): Job {
    return launch(
        context = IO,
        start = CoroutineStart.DEFAULT,
        block = block
    )
}
If I try to use this in place of the regular launch I get the following error:
java.lang.NoSuchMethodError: 'kotlinx.coroutines.Job com.some.misc.ExtensionsKt.launchIO(kotlinx.coroutines.CoroutineScope, kotlin.jvm.functions.Function2)'
I am more curious as to what I'm missing here rather than this being a serious use case
j

Joffrey

04/21/2022, 4:12 PM
NoSuchMethodError
usually sounds like the runtime classpath is missing something that was there at compile time. How are you compiling and running this code and the code that calls it?
c

cah

04/21/2022, 4:18 PM
This is part of a ktor project which I'm running using the gradle run task
j

Joffrey

04/21/2022, 4:50 PM
Is this a multi-module project? Maybe the module containing
launchIO
is declared as
compileOnly
dependency of the module using it?
j

julian

04/22/2022, 5:20 PM
@cah I'm able to compile and run your code without errors.