There is no way to thread the `B` type of `use` in...
# arrow
b
There is no way to thread the
B
type of
use
in
bracketCase
through the
ExitCase.Completed
part of
release
, is there?
s
Sounds like’d want 2 nested brackets for that. Could you share some sample code?
b
Copy code
fun doWork(
            workitem: Workitem,
            worker: (Id) -> Kind<F, String>
    ) = fx.monadThrow {
        !claim(workitem.id)
    }.bracketCase({ _, exitCase -> when(exitCase) {
        is ExitCase.Error -> releaseError(workitem.id, exitCase.e)
        is ExitCase.Canceled -> releaseError(workitem.id, IllegalStateException("Workitem ${workitem.id} cancelled"))
        is ExitCase.Completed -> releaseComplete(workitem.id, /* need String from worker */)
    }}) { withLockedItem(workitem.itemId, worker) }
withLockedItem
is another
bracket
that claims/releases another resource with
use: worker
releaseError
and
releaseComplete
work to modify identical fields in the same database record obtained by
!claim(workitem.id)