U
    Ã@Ûfî  ã                   @   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
   úH/var/www/html/chatgpt/venv/lib/python3.8/site-packages/eventlet/coros.pyÚ__init__   s    
zmetaphore.__init__é   c                 C   s2   |dkst ‚|  j|7  _| j|kr.| j ¡  dS )z‰Increment our counter. If this transitions the counter from zero to
        nonzero, make any subsequent :meth:`wait` call wait.
        r   N)ÚAssertionErrorr   r   Úreset©r	   Zbyr
   r
   r   Úinc   s    
zmetaphore.incc                 C   s8   |dkst ‚|  j|8  _| jdkr4d| _| j ¡  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
   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   )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   