[WIP] Introduce Arrow Fx#821
Conversation
| launch { | ||
| try { | ||
| fx { | ||
| !effect { |
There was a problem hiding this comment.
What's the purpose to use fx? 🤔
AFAIK, fx forces to represent side-effects by using suspend functions through compilation errors.
If you want to just integrate with coroutine, then arrow supports coroutine extension with DefferedK
val defferedK = async {
...
LoadingState.LOADED
}.k().handleErrorWith {
dispatcher.dispatch(
Action.ShowProcessingMessage(
Message.of(
R.string.session_favorite_connection_error
)
)
)
LoadingState.INITIALIZED
}
dispatcher.dispatch(defferedK.unsafeAttemptSync())
maybe be like above.
There was a problem hiding this comment.
There was a problem hiding this comment.
Yes. Probably .k and DeferredK will be removed. 😇
There was a problem hiding this comment.
After diving into arrow fx, I found a cause.
The current fx is for Try monad and it doesn't take care of asynchronous operations.
In FP world, IO monad is what you need to use.
- Add io.arrow-kt:arrow-effects-io-extensions dependency
- Import arrow.effects.extensions.io.fx.fx correctly
Then, follow the style below.
fun toggleFavorite(...) {
unsafe {
runNonBlocking({
fx {
....
}
}, { // Either monad will be coming
})
}
}
|
Currently, the coroutines are not canceled when coroutineContext is canceled. 😭 |
Apk comparision results
Generated by 🚫 Danger |
|
Asserted successfully. 💯 Generated by 🚫 Danger |
Overview (Required)