Hey friends, is it reasonable to run suspended fun...
# arrow
h
Hey friends, is it reasonable to run suspended functions within an IO? We're migrating from
IO
to
suspend
and wondering about interoperability. E.g. in this example,
myFun()
works as expected, despite
log(..)
being a suspended function. I believe this is because
IO
now uses
suspend
under the hood?
Copy code
import <http://arrow.fx.IO|arrow.fx.IO>
import kotlinx.coroutines.delay

suspend fun log(message: String) {
  delay(1000)
  println(message)
}

fun myFun(): IO<Unit> = IO {
  log("test")
}

myFun() // does nothing, suspended
myFun().unsafeRunSync() // logs "test"
r
Hi @Hugo, IO was in a way doble wrapping suspend. You can use IO in 0.12 alongside suspend as in your example but be aware that in 0.13 IO is gone. In your example translated to suspend you would push all of it’s running until the edge with
suspend fun main
or integrating with an endpoint that takes suspend or in Android in whatever compose handlers etc. Other than that suspend already covers all the use cases of IO. https://www.47deg.com/blog/arrow-0.13.0-release/ https://arrow-kt.io/docs/effects/io/
h
Thanks @raulraja! Sounds like we're on the right track then 👍
👍 1
r
Glad to hear, if you run into any issues migrating feel free to ping us 🙂