
    A'h
                         d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 ej                  dk\  Z G d de j                        Z G d d	ej                        Z G d
 d      ZddgZy)    N)deque)	monotonic)Optional)   
   c                       e Zd ZdZddZy)
AsyncQueuezlAsync unbounded FIFO queue with a wait() method.

    Subclassed from asyncio.Queue, adding a wait() method.Nc                   K   | j                         rwt        r| j                         j                         }n| j                  j                         }| j
                  j                  |       	 | d{    | j                         rvyy7 #  |j                          	 | j
                  j                  |       n# t        $ r Y nw xY w| j                         s+|j                         s| j                  | j
                          xY ww)zIf queue is empty, wait until an item is available.

        Copied from Queue.get(), removing the call to .get_nowait(),
        ie. this doesn't consume the item, just waits for it.
        N)emptyPY_310	_get_loopcreate_future_loop_gettersappendcancelremove
ValueError	cancelled_wakeup_next)selfgetters     \/home/kushmeetdev/Regenta/Chatbot/venv/lib/python3.12/site-packages/langgraph/utils/queue.pywaitzAsyncQueue.wait   s      jjl)779113MM  ( jjl MM((0!   zz|F,<,<,> %%dmm4sZ   A+D
.B 3B4B 8D
	D
B D B<;D<	CDC?DD
)returnN)__name__
__module____qualname____doc__r        r   r	   r	      s    >r!   r	   c                   (    e Zd ZdZddedee   fdZy)	Semaphorez(Semaphore subclass with a wait() method.Nblockingtimeoutc                 8   |s|t        d      d}d}| j                  5  | j                  dk(  rS|snR|#|t               |z   }n|t               z
  }|dk  rn-| j                  j	                  |       | j                  dk(  rSd}ddd       |S # 1 sw Y   |S xY w)z@Block until the semaphore can be acquired, but don't acquire it.Nz.can't specify timeout for non-blocking acquireFr   T)r   _cond_valuer   r   )r   r$   r%   rcendtimes        r   r   zSemaphore.wait5   s    G/MNNZZ 	++"&"++"7")IK"7"a<!

( ++" 	 		 	s   A"BBBTN)r   r   r   r   boolr   floatr   r    r!   r   r#   r#   2   s    2T 8E? r!   r#   c                   ^    e Zd ZdZd Zd	dZd	dZd	dZd Zd Z	 e
ej                        Zy)
	SyncQueuezqUnbounded FIFO queue with a wait() method.
    Adapted from pure Python implementation of queue.SimpleQueue.
    c                 B    t               | _        t        d      | _        y )Nr   )r   _queuer#   _countr   s    r   __init__zSyncQueue.__init__Q   s    glr!   Nc                 n    | j                   j                  |       | j                  j                          y)zPut the item on the queue.

        The optional 'block' and 'timeout' arguments are ignored, as this method
        never blocks.  They are provided for compatibility with the Queue class.
        N)r1   r   r2   release)r   itemblockr%   s       r   putzSyncQueue.putU   s&     	4 r!   c                     ||dk  rt        d      | j                  j                  ||      st        j                  	 | j
                  j                         S # t        $ r t        j                  w xY w)a  Remove and return an item from the queue.

        If optional args 'block' is true and 'timeout' is None (the default),
        block if necessary until an item is available. If 'timeout' is
        a non-negative number, it blocks at most 'timeout' seconds and raises
        the Empty exception if no item was available within that time.
        Otherwise ('block' is false), return an item if one is immediately
        available, else raise the Empty exception ('timeout' is ignored
        in that case).
        r   ''timeout' must be a non-negative number)r   r2   acquirequeueEmptyr1   popleft
IndexErrorr   r8   r%   s      r   getzSyncQueue.get^   sk     7Q;FGG{{""5'2++	;;&&(( 	++	s    A A4c                 `    ||dk  rt        d      | j                  j                  ||       y)z`If queue is empty, wait until an item maybe is available,
        but don't consume it.
        Nr   r;   )r   r2   r   rA   s      r   r   zSyncQueue.waitr   s0     7Q;FGG(r!   c                 2    t        | j                        dk(  S )zCReturn True if the queue is empty, False otherwise (not reliable!).r   lenr1   r3   s    r   r   zSyncQueue.emptyz   s    4;;1$$r!   c                 ,    t        | j                        S )z9Return the approximate size of the queue (not reliable!).rE   r3   s    r   qsizezSyncQueue.qsize~   s    4;;r!   r+   )r   r   r   r   r4   r9   rB   r   r   rH   classmethodtypesGenericAlias__class_getitem__r    r!   r   r/   r/   L   s8    #()%  $E$6$67r!   r/   )asyncior=   sys	threadingrJ   collectionsr   timer   typingr   version_infor   Queuer	   r#   r/   __all__r    r!   r   <module>rV      si      
     			W	$   F	## 468 68r 
%r!   