import * as tsplus_module_1 from "@effect/core/stm/TSemaphore/operations/acquireN";
import * as tsplus_module_2 from "@effect/core/stm/STM/operations/commit";
import * as tsplus_module_3 from "@effect/core/stm/TSemaphore/operations/releaseN";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/ensuring";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/zipRight";
import * as tsplus_module_6 from "@effect/core/io/Effect/operations/interruption";
/**
 * Executes the specified effect, acquiring the specified number of permits
 * immediately before the effect begins execution and releasing them
 * immediately after the effect completes execution, whether by success,
 * failure, or interruption.
 *
 * @tsplus fluent ets/TSemaphore withPermits
 */

export function withPermits_(self, permits, __tsplusTrace) {
  return effect => tsplus_module_6.uninterruptibleMask(({
    restore
  }) => tsplus_module_5.zipRight_(restore(() => tsplus_module_2.commit(tsplus_module_1.acquireN_(self, permits), __tsplusTrace), __tsplusTrace), () => tsplus_module_4.ensuring_(restore(() => effect, __tsplusTrace), () => tsplus_module_2.commit(tsplus_module_3.releaseN_(self, permits), __tsplusTrace), __tsplusTrace), __tsplusTrace), __tsplusTrace);
}
/**
 * Executes the specified effect, acquiring the specified number of permits
 * immediately before the effect begins execution and releasing them
 * immediately after the effect completes execution, whether by success,
 * failure, or interruption.
 *
 * @tsplus static ets/TSemaphore/Aspects withPermits
 */

export const withPermits = (permits, __tsplusTrace) => self => withPermits_(self, permits, __tsplusTrace);
//# sourceMappingURL=withPermits.mjs.map