���Z� � @ s/ d d l Z d d l Z Gd d � d � Z d S)� Nc @ sI e Z d Z d Z d d � Z d d d � Z d d � Z d d � Z d S)�EventResultOrErrorz� This class wrappers the Event asyncio lock allowing either awake the locked Tasks without any error or raising an exception. thanks to @vorpalsmith for the simple design. c C s: | | _ d | _ t j d | � | _ t j � | _ d S)N�loop)�_loop�_exc�asyncio�Event�_event�collections�deque�_waiters)�selfr � r � /locks.py�__init__ s zEventResultOrError.__init__Nc C s | | _ | j j � d S)N)r r �set)r �excr r r r s zEventResultOrError.setc � sj | j j | j j � � } | j j | � z | Id H} Wd | j j | � X| j d k rf | j � | S)N)r Zcreate_taskr �waitr �append�remover )r �waiter�valr r r r s zEventResultOrError.waitc C s"