import * as tsplus_module_1 from "@effect/core/io/Effect/operations/unit";
import * as tsplus_module_2 from "@effect/core/io/Cause/operations/failureOrCause";
import * as tsplus_module_3 from "@tsplus/stdlib/data/Either/fold";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/acquireUseReleaseExit";
/**
 * Runs the specified effect if this effect is terminated, either because of a
 * defect or because of interruption.
 *
 * @tsplus fluent ets/Effect onTermination
 */

export function onTermination_(self, cleanup, __tsplusTrace) {
  return tsplus_module_4.acquireUseReleaseExit(() => tsplus_module_1.unit, () => self, (_, exit) => exit._tag === "Failure" ? tsplus_module_3.fold_(tsplus_module_2.failureOrCause(exit.cause), () => tsplus_module_1.unit, cleanup) : tsplus_module_1.unit, __tsplusTrace);
}
/**
 * Runs the specified effect if this effect is terminated, either because of a
 * defect or because of interruption.
 *
 * @tsplus static ets/Effect/Aspects onTermination
 */

export const onTermination = (cleanup, __tsplusTrace) => self => onTermination_(self, cleanup, __tsplusTrace);
//# sourceMappingURL=onTermination.mjs.map