U
    uõ?dp  ã                   @   s6   d dl Z d dlZd dlmZmZmZ G dd„ dƒZdS )é    N)ÚAnyÚDequeÚOptionalc                   @   sT   e Zd ZdZejddœdd„Zdee ddœdd„Z	e
d	œd
d„Zdd	œdd„ZdS )ÚEventResultOrErrorzÓEvent asyncio lock helper class.

    Wraps the Event asyncio lock allowing either to awake the
    locked Tasks without any error or raising an exception.

    thanks to @vorpalsmith for the simple design.
    N)ÚloopÚreturnc                 C   s$   || _ d | _t ¡ | _t ¡ | _d S ©N)Ú_loopÚ_excÚasyncioÚEventÚ_eventÚcollectionsÚdequeÚ_waiters)Úselfr   © r   ú1/tmp/pip-unpacked-wheel-_pk67_um/aiohttp/locks.pyÚ__init__   s    
zEventResultOrError.__init__)Úexcr   c                 C   s   || _ | j ¡  d S r   )r
   r   Úset)r   r   r   r   r   r      s    zEventResultOrError.set)r   c              	   Ã   sP   | j  | j ¡ ¡}| j |¡ z|I d H }W 5 | j |¡ X | jd k	rL| j‚|S r   )r	   Zcreate_taskr   Úwaitr   ÚappendÚremover
   )r   ÚwaiterÚvalr   r   r   r      s    
zEventResultOrError.waitc                 C   s   | j D ]}| ¡  qdS )zCancel all waitersN)r   Úcancel)r   r   r   r   r   r   &   s    
zEventResultOrError.cancel)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZAbstractEventLoopr   r   ÚBaseExceptionr   r   r   r   r   r   r   r   r      s
   r   )r   r   Útypingr   r   r   r   r   r   r   r   Ú<module>   s   