
    &th
                     p    d dl 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 dgZ G d de          ZdS )    )AbstractEventLoopensure_futureFutureiscoroutine)AnyCallablecastDictOptionalSetTuple)EventEmitterAsyncIOEventEmitterc                   j     e Zd ZdZd
dee         f fdZdedee	df         de
ee	f         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loopc                     t          t          |                                            || _        t	                      | _        d S N)superr   __init___loopset_waiting)selfr   	__class__s     `/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/pyee/asyncio.pyr   zAsyncIOEventEmitter.__init__'   s6    !4((1133326
%(UU    fargs.kwargsc                     	  ||i |}t          |          rT j        r*t          t          t          |           j                  }nPt          t          t          |                    }n-t          |t                    rt          t          |          }nd S  fd}|                    |            j        	                    |           d S # t          $ r!}                     d|           Y d }~d S d }~ww xY w)N)r   c                     j                             |            |                                 rd S |                                 }|r                    d|           d S d S )Nerror)r   remove	cancelled	exceptionemit)r   excr   s     r   callbackz/AsyncIOEventEmitter._emit_run.<locals>.callbackE   sg    $$Q''';;== F!" ,IIgs+++++, ,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_run,   s'   	#4*6**D 4   : 9  -T#t__4:NNNCC'S$88CCD&)) 3oo, , , , , !!(+++Mc"""""9  	$ 	$ 	$IIgs#########	$s   C 
C<C77C<r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r
   strr/   __classcell__)r   s   @r   r   r      s         6+ +X&78 + + + + + +
$#$# CHo$# S#X	$# $# $# $# $# $# $# $#r   N)asyncior   r   r   r   typingr   r   r	   r
   r   r   r   	pyee.baser   __all__r    r   r   <module>r;      s    J I I I I I I I I I I I B B B B B B B B B B B B B B B B B B " " " " " " 
!E# E# E# E# E#, E# E# E# E# E#r   