import * as tsplus_module_1 from "@effect/core/stm/STM/operations/fail";
import * as tsplus_module_2 from "@effect/core/stm/STM/operations/zipRight";
import * as tsplus_module_3 from "@effect/core/stm/STM/operations/succeedNow";
import * as tsplus_module_4 from "@effect/core/stm/STM/operations/foldSTM";
/**
 * Executes the specified finalization transaction whether or
 * not this effect succeeds. Note that as with all STM transactions,
 * if the full transaction fails, everything will be rolled back.
 *
 * @tsplus fluent ets/STM ensuring
 */

export function ensuring_(self, finalizer) {
  return tsplus_module_4.foldSTM_(self, e => tsplus_module_2.zipRight_(finalizer, () => tsplus_module_1.fail(() => e)), a => tsplus_module_2.zipRight_(finalizer, () => tsplus_module_3.succeedNow(a)));
}
/**
 * Executes the specified finalization transaction whether or
 * not this effect succeeds. Note that as with all STM transactions,
 * if the full transaction fails, everything will be rolled back.
 *
 * @tsplus static ets/STM/Aspects ensuring
 */

export const ensuring = finalizer => self => ensuring_(self, finalizer);
//# sourceMappingURL=ensuring.mjs.map