"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.scoped = scoped;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Exit/operations/failCause"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Scope/operations/close"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/failCause"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/zipRight"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Tuple/make"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/succeedNow"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Scope/operations/extend"));

var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/foldCauseEffect"));

var tsplus_module_9 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/interruption"));

var tsplus_module_10 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Scope/operations/make"));

var tsplus_module_11 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/flatMap"));

var tsplus_module_12 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stream/Channel/operations/acquireUseReleaseOutExit"));

var tsplus_module_13 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stream/Channel/operations/mapOut"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const fileName_1 = "(@effect/core) _src/stream/Channel/operations/scoped.ts";

/**
 * Use a scoped effect to emit an output element.
 *
 * @tsplus static ets/Channel/Ops scoped
 */
function scoped(effect) {
  return tsplus_module_13.mapOut_(tsplus_module_12.acquireUseReleaseOutExit_(() => tsplus_module_11.flatMap_(tsplus_module_10.make, scope => tsplus_module_9.uninterruptibleMask(({
    restore
  }) => tsplus_module_8.foldCauseEffect_(restore(() => tsplus_module_7.extend_(scope, effect), fileName_1 + ":12:16"), cause => tsplus_module_4.zipRight_(tsplus_module_2.close_(scope, () => tsplus_module_1.failCause(cause)), () => tsplus_module_3.failCause(() => cause, fileName_1 + ":13:75"), fileName_1 + ":13:58"), out => tsplus_module_6.succeedNow(tsplus_module_5.make(out, scope), fileName_1 + ":14:37"), fileName_1 + ":12:54"), fileName_1 + ":11:33"), fileName_1 + ":10:23"), ({
    tuple: [_, scope]
  }, exit) => tsplus_module_2.close_(scope, () => exit)), _ => _.get(0));
}
//# sourceMappingURL=scoped.js.map