Repository navigation
Changed implementation TaskLocal#bind in terms of Task#bracket - #603
Conversation
Codecov Report
@@ Coverage Diff @@
## master #603 +/- ##
==========================================
- Coverage 90.85% 90.81% -0.04%
==========================================
Files 377 377
Lines 9979 9975 -4
Branches 1876 1882 +6
==========================================
- Hits 9066 9059 -7
- Misses 913 916 +3 |
| val saved = ref.value | ||
| ref.update(value) | ||
| task.doOnFinish(_ => restore(saved)) | ||
| task.bracket(r => Task.now(r))(_ => restore(saved)) |
There was a problem hiding this comment.
If you want to handle cancellation, task has to be used inside bracket. E.g.
Task.unit.bracket(_ => task)(_ => restore(saved))Also bindL needs to have similar change, so maybe it's easier to implement bind as bindL(Task.now(value))
…d in terms of bindL
|
@oleg-py So I redefined bindL like this: def bindL[R](value: Task[A])(task: Task[R]): Task[R] = {
val saved = ref.value
value.bracket { v =>
ref.update(v)
task
}(_ => restore(saved))
}Also, took care of |
| task.doOnFinish(_ => restore(saved)) | ||
| } | ||
| def bindL[R](value: Task[A])(task: Task[R]): Task[R] = { | ||
| val saved = ref.value |
There was a problem hiding this comment.
This ref.value should be suspended as well ...
Task.eval(ref.value).flatMap { saved =>
value.bracket {
ref.update(v)
task
} { _ =>
restore(saved)
}
}| ref.update(value) | ||
| task.doOnFinish(_ => restore(saved)) | ||
| } | ||
| Task.suspend(bindL(Task.now(value))(task)) |
There was a problem hiding this comment.
If you suspend that value as I mentioned below, you don't need to suspend here.
There was a problem hiding this comment.
@alexandru Understood, will take care of it later today.
|
@alexandru should I trigger another build? |
|
Please merge with master. |
…LocalBindWithBracket
|
Not 100% sure, but I think this is fine. Will merge for now. |
Addresses #601
Changes the
TaskLocal#bindimplementation in terms ofTask#bracketwhich handles any cleanup of resources upon success, failure or cancellation.