The current bracket operation cannot be interrupted during acquisition. This means if a lengthy acquisition is attempted, and the result is no longer needed, then the fiber executing the acquisition will "hang" for quite some time, until the acquisition is completed. It may be desirable in some cases to allow "fake interruption" of acquisition in a new combinator bracketFork.
A hypothetical bracketFork will allow instantaneous interruption during resource acquisition; but it will not actually interrupt the underlying acquisition, but rather, in a separate fiber, await the acquisition, and then gracefully and immediately release the resource after acquisition succeeds. Thus the fiber executing bracketFork will be able to be interrupted right away even if in the middle of a lengthy acquisition operation.
The bracketFork variants will have the exact same structure as existing bracket combinators. Probably, we can get away with fewer and more common variants.
Existing definition of bracketExit is as follows:
ZIO.uninterruptibleMask[R, E, B](
restore =>
acquire.flatMap({ a =>
restore(use(a)).run.flatMap( { e =>
release(a, e).foldCauseM(
cause2 => ZIO.halt(e.fold(_ ++ cause2, _ => cause2)),
_ => ZIO.done(e)
)
})
})
)
I would like to give this a go.
Awesome.
I think it would be helpful to define: ZIO.interruptibleFork for this one. This method would give you back something that is interruptible, but actually doesn't necessarily interrupt the effect it is called on (rather it disconnects its interruption from the parent).
Cool! I think I will create a WIP PR to make sure I am understanding you correctly.
@dariusrobson did you pick this up? This looks interesting, have you made progress?
Most helpful comment
I would like to give this a go.