Marcin Gryszko
06/19/2019, 5:37 AMIO? (I'm a bit lost in the forest of IO, Async and fx constructors and combinators). Take this example:
suspend fun getCoroutines(internalHotelId: Int): Either<Throwable, CustomerFeedback?> { ... }
I'd like to execute it asynchronously. This is my take:
fun getIOAsync(internalHotelId: Int): IO<CustomerFeedback?> =
IO.async().async { callback ->
GlobalScope.launch {
val result = GlobalScope.async { getCoroutines(internalHotelId) }.await()
callback.invoke(result)
}
}
}
Is this the correct way? Are there any other ways?
Can this be achieved with fx and effect?raulraja
06/19/2019, 8:36 AMfun getIOAsync(internalHotelId: Int): IO<CustomerFeedback?> = fx {
val suspendedEffect = effect { getCoroutines(internalHotelId) }
val fiber = !NonBlocking.startFiber(suspendedEffect)
!fiber.join()
}
Or after 0.10.0 which we are working towards right now you can also do:
IO.effect(NonBlocking) { getCoroutines(internalHotelId) }
where NonBlocking is the ctx you want to run your fiber on.Marcin Gryszko
06/20/2019, 5:10 AMraulraja
06/20/2019, 7:22 AM