import * as tsplus_module_1 from "@effect/core/stm/TRef/operations/unsafeGet";
import * as tsplus_module_2 from "@tsplus/stdlib/structure/Equals";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/ImmutableQueue/splitAt";
import * as tsplus_module_4 from "@effect/core/stm/TRef/operations/unsafeSet";
import * as tsplus_module_5 from "@tsplus/stdlib/collections/Chunk/definition";
import * as tsplus_module_6 from "@effect/core/stm/STM/operations/effect";
import { STMInterruptException } from "@effect/core/stm/STM";
import { concreteTQueue } from "@effect/core/stm/TQueue/operations/_internal/InternalTQueue";
/**
 * Takes up to the specified number of values from the queue.
 *
 * @tsplus fluent ets/TQueue takeUpTo
 */

export function takeUpTo_(self, max) {
  void 0;
  return tsplus_module_6.effect((journal, fiberId) => {
    const queue = tsplus_module_1.unsafeGet_(self.ref, journal);

    if (tsplus_module_2.equals(queue, null)) {
      throw new STMInterruptException(fiberId);
    }

    const {
      tuple: [toTake, remaining]
    } = tsplus_module_3.splitAt_(queue, max);
    tsplus_module_4.unsafeSet_(self.ref, remaining, journal);
    return tsplus_module_5.from(toTake);
  });
}
/**
 * Takes up to the specified number of values from the queue.
 *
 * @tsplus static ets/TQueue/Aspects takeUpTo
 */

export const takeUpTo = max => self => takeUpTo_(self, max);
//# sourceMappingURL=takeUpTo.mjs.map