-
Notifications
You must be signed in to change notification settings - Fork 433
Enable coroutine support in gradle script #292
Comments
@metjka yeah I can use coroutine in my kotlin app, but this issue is to enable it in the gradle script. |
I mistakenly assumed coroutines were not enabled by default but this sample works for me with the latest snapshot distro: // build.gradle.kts
import kotlin.coroutines.experimental.*
fun fib() = buildSequence {
var a = 0
var b = 1
while (true) {
yield(b)
val next = a + b
a = b; b = next
}
}
task("fib") {
doLast {
fib().take(5).forEach(::println)
}
} Is there anything else that needs to be done? |
@bamboo yeah I can use all the coroutines functionalities from As you can see none of the extensions/classes are exposed in build script for So the question is, can I use |
@sureshg I don't know what's happening with content assist there but the following works for me: import kotlinx.coroutines.experimental.*
buildscript {
dependencies {
classpath("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.12")
}
repositories {
gradleScriptKotlin()
}
}
// Run it with ./gradlew async -q
task("async") {
doLast {
runBlocking { // start main coroutine
launch(CommonPool) { // create new coroutine in common thread pool
delay(1000L)
println("World!")
}
println("Hello,") // main coroutine continues while child is delayed
delay(2000L) // non-blocking delay for 2 seconds to keep JVM alive
}
}
} |
@bamboo thanks! Really not sure what happened earlier. Your example works fine. You can close this issue now. |
Right now there are no way to use coroutines (
kotlinx.coroutines.experimental.*
) functionalities from gradle script (say call asuspendable
function from gradle task). Tried to add all the coroutines dependencies tobuildscript
classpath, but it still not working.The text was updated successfully, but these errors were encountered: