import * as tsplus_module_1 from "@effect/core/io/Cause/definition";
import * as tsplus_module_2 from "@effect/core/io/Exit/operations/fold";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/failCause";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/done";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/suspendSucceed";
import * as tsplus_module_6 from "@effect/core/io/Effect/operations/foldCauseEffect";
import * as tsplus_module_7 from "@effect/core/io/Effect/operations/exit";
import * as tsplus_module_8 from "@effect/core/io/Effect/operations/flatMap";
import * as tsplus_module_9 from "@effect/core/io/Effect/operations/interruption";
/**
 * Acquires a resource, uses the resource, and then releases the resource.
 * Neither the acquisition nor the release will be interrupted, and the
 * resource is guaranteed to be released, so long as the `acquire` effect
 * succeeds. If `use` fails, then after release, the returned effect will fail
 * with the same error.
 *
 * @tsplus static ets/Effect/Ops acquireUseReleaseExit
 * @tsplus fluent ets/Effect acquireUseReleaseExit
 */

export function acquireUseReleaseExit(acquire, use, release, __tsplusTrace) {
  return tsplus_module_9.uninterruptibleMask(({
    restore
  }) => tsplus_module_8.flatMap_(acquire(), a => tsplus_module_8.flatMap_(tsplus_module_7.exit(tsplus_module_5.suspendSucceed(() => restore(() => use(a), __tsplusTrace), __tsplusTrace), __tsplusTrace), exit => tsplus_module_6.foldCauseEffect_(tsplus_module_5.suspendSucceed(() => release(a, exit), __tsplusTrace), cause2 => tsplus_module_3.failCause(() => tsplus_module_2.fold_(exit, cause1 => tsplus_module_1.combineSeq(cause1, cause2), () => cause2), __tsplusTrace), () => tsplus_module_4.done(() => exit, __tsplusTrace), __tsplusTrace), __tsplusTrace), __tsplusTrace), __tsplusTrace);
}
//# sourceMappingURL=acquireUseReleaseExit.mjs.map