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/head";
import * as tsplus_module_4 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_5 from "@effect/core/stm/STM/operations/effect";
import { STMInterruptException, STMRetryException } from "@effect/core/stm/STM";
import { concreteTQueue } from "@effect/core/stm/TQueue/operations/_internal/InternalTQueue";
/**
 * Views the next element in the queue without removing it, retrying if the
 * queue is empty.
 *
 * @tsplus getter ets/TQueue peek
 */

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

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

    const first = tsplus_module_3.head(queue);

    if (tsplus_module_4.isSome(first)) {
      return first.value;
    }

    throw new STMRetryException();
  });
}
//# sourceMappingURL=peek.mjs.map