-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Introduce Arrow Fx #821
base: master
Are you sure you want to change the base?
Conversation
launch { | ||
try { | ||
fx { | ||
!effect { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Probably .k and DeferredK will be removed. 😇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. 😭 |
.../io/github/droidkaigi/confsched2019/session/ui/actioncreator/SessionContentsActionCreator.kt
Outdated
Show resolved
Hide resolved
.../io/github/droidkaigi/confsched2019/session/ui/actioncreator/SessionContentsActionCreator.kt
Outdated
Show resolved
Hide resolved
.../io/github/droidkaigi/confsched2019/session/ui/actioncreator/SessionContentsActionCreator.kt
Outdated
Show resolved
Hide resolved
.../io/github/droidkaigi/confsched2019/session/ui/actioncreator/SessionContentsActionCreator.kt
Outdated
Show resolved
Hide resolved
.../io/github/droidkaigi/confsched2019/session/ui/actioncreator/SessionContentsActionCreator.kt
Outdated
Show resolved
Hide resolved
Apk comparision results
Generated by 🚫 Danger |
Asserted successfully. 💯 Generated by 🚫 Danger |
Overview (Required)