o
    ¨Ýjî  ã                   @   s   d dl mZ G dd„ dƒZdS )é    )Úeventc                   @   s4   e Zd ZdZdd„ Zddd„Zddd„Zd	d
„ ZdS )Ú	metaphorea  This is sort of an inverse semaphore: a counter that starts at 0 and
    waits only if nonzero. It's used to implement a "wait for all" scenario.

    >>> from eventlet import coros, spawn_n
    >>> count = coros.metaphore()
    >>> count.wait()
    >>> def decrementer(count, id):
    ...     print("{0} decrementing".format(id))
    ...     count.dec()
    ...
    >>> _ = spawn_n(decrementer, count, 'A')
    >>> _ = spawn_n(decrementer, count, 'B')
    >>> count.inc(2)
    >>> count.wait()
    A decrementing
    B decrementing
    c                 C   s   d| _ t ¡ | _| j ¡  d S )Nr   )ÚcounterÚ_eventÚEventr   Úsend©Úself© r
   úI/var/www/html/chatgpt/venv/lib/python3.10/site-packages/eventlet/coros.pyÚ__init__   s   
zmetaphore.__init__é   c                 C   s6   |dksJ ‚|  j |7  _ | j |kr| j ¡  dS dS )z‰Increment our counter. If this transitions the counter from zero to
        nonzero, make any subsequent :meth:`wait` call wait.
        r   N)r   r   Úreset©r	   Zbyr
   r
   r   Úinc   s
   
ûzmetaphore.incc                 C   s<   |dksJ ‚|  j |8  _ | j dkrd| _ | j ¡  dS dS )z–Decrement our counter. If this transitions the counter from nonzero
        to zero, a current or subsequent wait() call need no longer wait.
        r   N)r   r   r   r   r
   r
   r   Údec*   s   
ûzmetaphore.decc                 C   s   | j  ¡  dS )zŠSuspend the caller only if our count is nonzero. In that case,
        resume the caller once the count decrements to zero again.
        N)r   Úwaitr   r
   r
   r   r   7   s   zmetaphore.waitN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r
   r
   r
   r   r      s    

r   N)Zeventletr   r   r   r
   r
   r
   r   Ú<module>   s    