"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeExit_ = exports.makeExit = void 0;
// ets_tracing: off
const Tp = __importStar(require("../Collections/Immutable/Tuple"));
const Function_1 = require("../Function");
const T = __importStar(require("./deps-core"));
const managed_1 = require("./managed");
const add = __importStar(require("./ReleaseMap/add"));
/**
 * Lifts a `Effect< R, E, A>` into `Managed< R, E, A>` with a release action
 * that handles `Exit`. The acquire and release actions will be performed uninterruptibly.
 *
 * @ets_data_first makeExit_
 */
function makeExit(release, __trace) {
    return (acquire) => makeExit_(acquire, release, __trace);
}
exports.makeExit = makeExit;
/**
 * Lifts a `Effect< R, E, A>` into `Managed< R, E, A>` with a release action
 * that handles `Exit`. The acquire and release actions will be performed uninterruptibly.
 */
function makeExit_(acquire, release, __trace) {
    return new managed_1.Managed(T.uninterruptible((T.map_(T.bind_(T.bind_(T.bind_(T.do, "r", () => T.environment()), "a", (s) => T.provideAll_(acquire, s.r.get(0)), __trace), "rm", (s) => add.add((ex) => T.provideAll_(release(s.a, ex), s.r.get(0), __trace))(s.r.get(1))), (s) => Tp.tuple(s.rm, s.a)))));
}
exports.makeExit_ = makeExit_;
//# sourceMappingURL=makeExit.js.map