arrow-fx / arrow.fx / Promise / bracket

bracket

fun <F, A, B, C> bracket(ref: Ref<F, A>, use: (Promise<F, B>, A) -> Tuple2<Kind<F, C>, A>, release: (C, Promise<F, B>) -> Kind<F, Unit>, CF: Concurrent<F>): Kind<F, B>

This allows atomic modification of a Ref, and in its use function it also passes a Promise that defers the triggering of release until completed. This allows for use-cases such as a blocking offer for Queue where the offer is deferred until there is available capacity in the Queue. When there is capacity available, the putter will put the value in the Queue and complete the Promise so that the release function can do the clean-up.

Do you like Arrow?

Arrow Org
<