than_
01/20/2020, 3:00 PMcontinueOn(NonCancellable)? this snippet prints only STARTED :/
import <http://arrow.fx.IO|arrow.fx.IO>
import arrow.fx.extensions.fx
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.delay
val io = IO.fx {
continueOn(NonCancellable)
effect { println("STARTED") }.bind()
effect { delay(10000) }.bind()
effect { println("FINISHED") }.bind()
}
val disposable = io.unsafeRunAsyncCancellable { }
disposable()than_
01/20/2020, 3:09 PMsuspend fun foo() {
withContext(NonCancellable) {
println("STARTED")
delay(10000)
println("FINISHED")
}
}
val io = IO.effect(::foo)
val disposable = io.unsafeRunAsyncCancellable { }
disposable()
again prints only STARTEDsimon.vergauwen
01/20/2020, 4:40 PMio.uncancelable() on the resulting IO instead 😉than_
01/20/2020, 9:33 PMsimon.vergauwen
01/21/2020, 8:51 AMsuspend fun foo() {
withContext(NonCancellable) {
println("STARTED")
delay(100)
println("FINISHED")
}
}
fun main() {
val io = IO.effect(::foo)
val disposable = io.unsafeRunAsyncCancellable { }
disposable()
}
This only prints STARTED because delay switches threads, and thus the main thread finishes immediately after that resulting in Process finished with exit code 0.
effect is actually not cancelable, we’re hoping to fix KotlinX support but KotlinX wires cancelation in an implicit way under the hood and interopt requires a hard-dependency 😞
We’re still looking for a good solution. Roman said @ KotlinConf they’re thinking about moving it to the std so libraries can work together better.simon.vergauwen
01/21/2020, 8:51 AMSTARTED
FINISHED
Process finished with exit code 0simon.vergauwen
01/21/2020, 8:52 AMthan_
01/21/2020, 8:58 AMsimon.vergauwen
01/21/2020, 9:07 AM