hi. does IO support `continueOn(NonCancellable)`? ...
# arrow
t
hi. does IO support
continueOn(NonCancellable)
? this snippet prints only STARTED :/
Copy code
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()
this can be a bit surprising in cases like this
Copy code
suspend fun foo() {
    withContext(NonCancellable) {
        println("STARTED")
        delay(10000)
        println("FINISHED")
    }
}

val io = IO.effect(::foo)
val disposable = io.unsafeRunAsyncCancellable { }
disposable()
again prints only STARTED
s
No it does not but you can use
io.uncancelable()
on the resulting
IO
instead 😉
🔝 1
t
thanks. are there any plans for supporting it in the future or is this working as intended?
s
@than_ Hi, I was looking into this again and I think your assertion was incorrect.
Copy code
suspend 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.
This prints
Copy code
STARTED
FINISHED

Process finished with exit code 0
@aballano & @danieeh are looking into how we can improve KotlinX support for Arrow Fx
arrow 1
t
You are totally right. My bad. Thanks for your time 🙂
s
No problem! You’re very welcome 🙂