import * as tsplus_module_1 from "@effect/core/stm/TRef/operations/unsafeGet";
import * as tsplus_module_2 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_3 from "@effect/core/stm/STM/operations/effect";
import { STMInterruptException } 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, returning `None`
 * if the queue is empty.
 *
 * @tsplus getter ets/THub/TDequeue peekMaybe
 */

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

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

    let a = tsplus_module_2.none;
    let loop = true;

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

      if (node == null) {
        a = tsplus_module_2.none;
        loop = false;
      } else {
        const head = node.head;
        const tail = node.tail;

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

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