"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.parallelism = parallelism;
exports.parallelismWith = parallelismWith;
exports.withParallelism = void 0;
exports.withParallelismUnbounded = withParallelismUnbounded;
exports.withParallelism_ = withParallelism_;

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

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

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

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/definition"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/FiberRef/operations/locally"));

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

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; }

/**
 * Retrieves the maximum number of fibers for parallel operators or `None` if
 * it is unbounded.
 *
 * @tsplus static ets/Effect/Ops parallelism
 */
function parallelism(__tsplusTrace) {
  return tsplus_module_2.get(tsplus_module_1.currentParallelism.value, __tsplusTrace);
}
/**
 * Retrieves the current maximum number of fibers for parallel operators and
 * uses it to run the specified effect.
 *
 * @tsplus static ets/Effect/Ops parallelismWith
 */


function parallelismWith(f, __tsplusTrace) {
  return tsplus_module_3.getWith_(tsplus_module_1.currentParallelism.value, f, __tsplusTrace);
}
/**
 * Runs the specified effect with the specified maximum number of fibers for
 * parallel operators.
 *
 * @tsplus fluent ets/Effect withParallelism
 */


function withParallelism_(self, n, __tsplusTrace) {
  return tsplus_module_6.suspendSucceed(() => tsplus_module_5.locally_(tsplus_module_1.currentParallelism.value, tsplus_module_4.some(n), __tsplusTrace)(self), __tsplusTrace);
}
/**
 * Runs the specified effect with the specified maximum number of fibers for
 * parallel operators.
 *
 * @tsplus static ets/Effect/Aspects withParallelism
 */


const withParallelism = (n, __tsplusTrace) => self => withParallelism_(self, n, __tsplusTrace);
/**
 * Runs the specified effect with an unbounded maximum number of fibers for
 * parallel operators.
 *
 * @tsplus fluent ets/Effect withParallelismUnbounded
 */


exports.withParallelism = withParallelism;

function withParallelismUnbounded(self, __tsplusTrace) {
  return tsplus_module_6.suspendSucceed(() => tsplus_module_5.locally_(tsplus_module_1.currentParallelism.value, tsplus_module_4.none, __tsplusTrace)(self), __tsplusTrace);
}
//# sourceMappingURL=parallelism.js.map