"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.onError_ = exports.onError = exports.onExit = exports.onExit_ = void 0;
const bracketExit_1 = require("./bracketExit");
const core_1 = require("./core");
/**
 * Execute a cleanup function when the effect completes
 */
function onExit_(self, cleanup, __trace) {
    return (0, bracketExit_1.bracketExit_)(core_1.unit, () => self, (_, e) => cleanup(e), __trace);
}
exports.onExit_ = onExit_;
/**
 * Execute a cleanup function when the effect completes
 *
 * @ets_data_first onExit_
 */
function onExit(cleanup, __trace) {
    return (self) => onExit_(self, cleanup, __trace);
}
exports.onExit = onExit;
/**
 * Execute a cleanup function when the effect errors
 *
 * @ets_data_first onError_
 */
function onError(cleanup, __trace) {
    return (self) => onError_(self, cleanup, __trace);
}
exports.onError = onError;
/**
 * Execute a cleanup function when the effect errors
 */
function onError_(self, cleanup, __trace) {
    return onExit_(self, (e) => {
        switch (e._tag) {
            case "Failure": {
                return cleanup(e.cause);
            }
            case "Success": {
                return core_1.unit;
            }
        }
    }, __trace);
}
exports.onError_ = onError_;
//# sourceMappingURL=onExit.js.map