§
    �’jÊ  ã                   óx   — d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZ d dlmZ eZdgZ G d„ de¦  «        ZdS )é    )ÚAbstractEventLoopÚensure_futureÚFutureÚiscoroutineÚwait)ÚAnyÚCallableÚcastÚDictÚOptionalÚSetÚTuple)ÚEventEmitterÚAsyncIOEventEmitterc            
       óÚ   ‡ — e Zd ZdZddedee         ddfˆ fd„Zdedede	d	e	de
f
ˆ fd
„Zdededee	df         d	eee	f         ddf
d„Zdeddfd„Zdeddfd„Zedede
fd„¦   «         Zˆ xZS )r   a(  An event emitter class which can run asyncio coroutines in addition to
    synchronous blocking functions. For example:

    ```py
    @ee.on('event')
    async def async_handler(*args, **kwargs):
        await returns_a_future()
    ```

    On emit, the event emitter  will automatically schedule the coroutine using
    `asyncio.ensure_future` and the configured event loop (defaults to
    `asyncio.get_event_loop()`).

    Unlike the case with the EventEmitter, all exceptions raised by
    event handlers are automatically emitted on the `error` event. This is
    important for asyncio coroutines specifically but is also handled for
    synchronous functions for consistency.

    When `loop` is specified, the supplied event loop will be used when
    scheduling work with `ensure_future`. Otherwise, the default asyncio
    event loop is used.

    For asyncio coroutine event handlers, calling emit is non-blocking.
    In other words, you do not have to await any results from emit, and the
    coroutine is scheduled in a fire-and-forget fashion.
    NÚselfÚloopÚreturnc                 óŠ   •— t          t          | ¦  «                             ¦   «          || _        t	          ¦   «         | _        d S ©N)Úsuperr   Ú__init__Ú_loopÚsetÚ_waiting)r   r   Ú	__class__s     €ú:C:\Projects\DSCons\.venv\Lib\site-packages\pyee\asyncio.pyr   zAsyncIOEventEmitter.__init__)   s6   ø€ ÝÕ! 4Ñ(Ô(×1Ò1Ñ3Ô3Ð3Ø26ˆŒ
Ý%(¡U¤UˆŒˆˆó    ÚeventÚargsÚkwargsc                 ó>   •—  t          ¦   «         j        |g|¢R i |¤ŽS )a�  Emit `event`, passing `*args` and `**kwargs` to each attached
        function or coroutine. Returns `True` if any functions are attached to
        `event`; otherwise returns `False`.

        Example:

        ```py
        ee.emit('data', '00101001')
        ```

        Assuming `data` is an attached function, this will call
        `data('00101001')'`.

        When executing coroutine handlers, their respective futures will be
        stored in a "waiting" state. These futures may be waited on or
        canceled with `wait_for_complete` and `cancel`, respectively; and
        their status may be checked via the `complete` property.
        )r   Úemit)r   r   r    r!   r   s       €r   r#   zAsyncIOEventEmitter.emit.   s+   ø€ ð0 �u‰wŒwŒ|˜EÐ3 DÐ3Ð3Ð3¨FÐ3Ð3Ð3r   Úf.c                 ó  ‡ — 	  ||i |¤Ž}t          |¦  «        rT‰ j        r*t          t          t          |¦  «        ‰ j        ¬¦  «        }nPt          t          t          |¦  «        ¦  «        }n-t          |t          ¦  «        rt          t          |¦  «        }nd S dt          dd fˆ fd„}|                     |¦  «         ‰ j         	                    |¦  «         d S # t          $ r!}‰                      d|¦  «         Y d }~d S d }~ww xY w)N)r   r$   r   c                 óÄ   •— ‰j                              | ¦  «         |                      ¦   «         rd S |                      ¦   «         }|r‰                     d|¦  «         d S d S )NÚerror)r   ÚdiscardÚ	cancelledÚ	exceptionr#   )r$   Úexcr   s     €r   Úcallbackz/AsyncIOEventEmitter._emit_run.<locals>.callbacka   sg   ø€ Ø”×%Ò% aÑ(Ô(Ð(à—;’;‘=”=ð Ø�Fà/0¯{ª{©}¬}�Øð ,Ø—I’I˜g sÑ+Ô+Ð+Ð+Ð+ð,ð ,r   r'   )r   r   r   r
   r   Ú
isinstancer   Úadd_done_callbackr   ÚaddÚ	Exceptionr#   )r   r$   r    r!   ÚcoroÚfutr,   r+   s   `       r   Ú	_emit_runzAsyncIOEventEmitter._emit_runH   s:  ø€ ð	#Ø˜˜4Ð* 6Ð*Ð*ˆDõ ˜4Ñ Ô ð Ø”:ð 9õ  -­Tµ#°t©_¬_À4Ä:ÐNÑNÔN�C�Cå'­­S°$©¬Ñ8Ô8�C�Cå˜D¥&Ñ)Ô)ð Ý�3 ‘o”o��à�ð,�Fð , tð ,ð ,ð ,ð ,ð ,ð ,ð ×!Ò! (Ñ+Ô+Ð+ØŒM×Ò˜cÑ"Ô"Ð"Ð"Ð"øõ9 ð 	$ð 	$ð 	$Ø�IŠI�g˜sÑ#Ô#Ð#Ð#Ð#Ð#Ð#Ð#Ð#øøøøð	$øøøs   ƒC Ã
DÃ%DÄDc              ƒ   óP   K  — | j         rt          | j         ¦  «        ƒ d{V —† dS dS )a  Waits for all pending tasks to complete. For example:

        ```py
        @ee.on('event')
        async def async_handler(*args, **kwargs):
            await returns_a_future()

        # Triggers execution of async_handler
        ee.emit('data', '00101001')

        await ee.wait_for_complete()

        # async_handler has completed execution
        ```

        This is useful if you're attempting a graceful shutdown of your
        application and want to ensure all coroutines have completed execution
        beforehand.
        N)r   r   ©r   s    r   Úwait_for_completez%AsyncIOEventEmitter.wait_for_completen   sD   è è € ð( Œ=ð 	&Ý�t”}Ñ%Ô%Ð%Ð%Ð%Ð%Ð%Ð%Ð%Ð%Ð%ð	&ð 	&r   c                 óÄ   — | j         D ]>}|                     ¦   «         s(|                     ¦   «         s|                     ¦   «          Œ?| j                              ¦   «          dS )aò  Cancel all pending tasks. For example:

        ```py
        @ee.on('event')
        async def async_handler(*args, **kwargs):
            await returns_a_future()

        # Triggers execution of async_handler
        ee.emit('data', '00101001')

        ee.cancel()

        # async_handler execution has been canceled
        ```

        This is useful if you're attempting to shut down your application and
        attempts at a graceful shutdown via `wait_for_complete` have failed.
        N)r   Údoner)   ÚcancelÚclear)r   r2   s     r   r9   zAsyncIOEventEmitter.cancel…   s\   € ð& ”=ð 	ð 	ˆCØ—8’8‘:”:ð  c§m¢m¡o¤oð Ø—
’
‘”�øØŒ×ÒÑÔÐÐÐr   c                 ó   — | j          S )a  When true, there are no pending tasks, and execution is complete.
        For example:

        ```py
        @ee.on('event')
        async def async_handler(*args, **kwargs):
            await returns_a_future()

        # Triggers execution of async_handler
        ee.emit('data', '00101001')

        # async_handler is still running, so this prints False
        print(ee.complete)

        await ee.wait_for_complete()

        # async_handler has completed execution, so this prints True
        print(ee.complete)
        ```
        )r   r5   s    r   ÚcompletezAsyncIOEventEmitter.complete�   s   € ð, ”=Ð Ð r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚSelfr   r   r   Ústrr   Úboolr#   r	   r   r   r3   r6   r9   Úpropertyr<   Ú__classcell__)r   s   @r   r   r      sx  ø€ € € € € ðð ð6+ð +�tð + 8Ð,=Ô#>ð +È$ð +ð +ð +ð +ð +ð +ð
4Øð4àð4ð ð4ð ð	4ð
 
ð4ð 4ð 4ð 4ð 4ð 4ð4$#Øð$#àð$#ð �C˜�HŒoð$#ð �S˜#�X”ð	$#ð
 
ð$#ð $#ð $#ð $#ðL& dð &¨tð &ð &ð &ð &ð.�Tð ˜dð ð ð ð ð0 ð!�tð ! ð !ð !ð !ñ „Xð!ð !ð !ð !ð !r   N)Úasyncior   r   r   r   r   Útypingr   r	   r
   r   r   r   r   Ú	pyee.baser   rA   Ú__all__r   © r   r   ú<module>rK      sÅ   ðð PÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OØ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ Bà "Ð "Ð "Ð "Ð "Ð "à
€à Ð
!€ðf!ð f!ð f!ð f!ð f!˜,ñ f!ô f!ð f!ð f!ð f!r   