import * as tsplus_module_1 from "@effect/core/stm/TRef/operations/unsafeGet";
import * as tsplus_module_2 from "@effect/core/stm/STM/operations/effect";
import { STMInterruptException, STMRetryException } from "@effect/core/stm/STM";
import { concreteTDequeue } from "@effect/core/stm/THub/operations/_internal/InternalTDequeue";
/**
 * Views the next element in the queue without removing it, retrying if the
 * queue is empty.
 *
 * @tsplus getter ets/THub/TDequeue peek
 */

export function peek(self) {
  void 0;
  return tsplus_module_2.effect((journal, fiberId) => {
    let currentSubscriberHead = tsplus_module_1.unsafeGet_(self.subscriberHead, journal);

    if (currentSubscriberHead == null) {
      throw new STMInterruptException(fiberId);
    }

    let a = undefined;
    let loop = true;

    while (loop) {
      const node = tsplus_module_1.unsafeGet_(currentSubscriberHead, journal);

      if (node == null) {
        throw new STMRetryException();
      }

      const head = node.head;
      const tail = node.tail;

      if (head != null) {
        a = node.head;
        loop = false;
      } else {
        currentSubscriberHead = tail;
      }
    }

    return a;
  });
}
//# sourceMappingURL=peek.mjs.map