Danilo Herrera
09/20/2019, 2:59 PMIO.fx { ... }
? I tried starting the block with continueOn(<http://Dispatchers.IO|Dispatchers.IO>)
but for some reason it hangs.Bob Glamm
09/20/2019, 3:41 PMDanilo Herrera
09/20/2019, 3:49 PMcontinueOn
is meant to be used with async
and not fx
?Bob Glamm
09/20/2019, 3:53 PMcontinueOn
example it may be that you will need to use that combinator outside of the fx
blockBob Glamm
09/20/2019, 3:53 PMBob Glamm
09/20/2019, 3:54 PMDanilo Herrera
09/20/2019, 3:55 PMIO.fx {
continueOn(<http://Dispatchers.IO|Dispatchers.IO>)
val inventory = !requestOperations.getInventory()
continueOn(Dispatchers.Main)
inventoryLiveData.value = inventory
}
.attempt()
.unsafeRunSync()
.fold(
ifLeft = {
// handle error
},
ifRight = {
// completed
}
)
Bob Glamm
09/20/2019, 3:58 PMIO.unit.continueOn(Dispatchers.Main).flatMap { IO.fx { ... } }
Bob Glamm
09/20/2019, 3:58 PMDanilo Herrera
09/20/2019, 4:09 PMBob Glamm
09/20/2019, 4:10 PMcontinueOn
has to happen at IO "program" boundariesBob Glamm
09/20/2019, 4:11 PMIO.continueOn(...).flatMap(IO).continueOn(...).flatMap(IO)...
Bob Glamm
09/20/2019, 4:11 PMpakoito
09/20/2019, 4:13 PMunsafeRunSync
you’re blocking the current thread, which I’ll assume is the main thread. Then inside the IO you try to return back but it’s blockedpakoito
09/20/2019, 4:13 PMunsafeRunAsync { /* NOTHING */ }
and it you want to display something on the UI do it on the fx blockpakoito
09/20/2019, 4:14 PMpakoito
09/20/2019, 4:15 PMmyOperation.observeOn(Main).subscribe { ui() }
where it should be
myOperation.observeOn(Main).flatMap { ui() }.subscribe { /* unrecoverable exception + crash */ }
pakoito
09/20/2019, 4:16 PMsubscribe
is unsafeRunAsync
, whereas unsafeRynSync
is blockingFirst
Danilo Herrera
09/20/2019, 4:19 PMunsafeRunAsync
?Danilo Herrera
09/20/2019, 4:24 PMunsafeRunSync
was the precise reason it was hanging! Got it to work with the async version:
IO.fx {
continueOn(<http://Dispatchers.IO|Dispatchers.IO>)
val inventory = !requestOperations.getInventory()
continueOn(Dispatchers.Main)
inventoryLiveData.value = inventory
}
.unsafeRunAsync {
it.fold(
ifLeft = {
// handle error
},
ifRight = {
// completed
}
)
}
raulraja
09/20/2019, 4:34 PMraulraja
09/20/2019, 4:34 PMraulraja
09/20/2019, 4:34 PMDanilo Herrera
09/20/2019, 4:42 PMpakoito
09/20/2019, 10:43 PMso would you handle errors within.handleErrorWith before you run itunsafeRunAsync
pakoito
09/20/2019, 10:43 PMpakoito
09/20/2019, 10:44 PM!requestOperations.getInventory()
.handleError { showErrorUI() }
for the whole thing
IO. fx { ... }
.handleErrorWith {
effect(UI) { showErrorUI() }
}