
    5j
                     h    S SK JrJrJrJr  S SKJrJrJrJ	r	J
r
JrJr  S SKJr  S/r " S S\5      rg)    )AbstractEventLoopensure_futureFutureiscoroutine)AnyCallablecastDictOptionalSetTuple)EventEmitterAsyncIOEventEmitterc                   h   ^  \ rS rSrSrSS\\   4U 4S jjjrS\S\	\
S4   S\\\
4   4S	 jrS
rU =r$ )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.
loopc                 T   > [         [        U ]  5         Xl        [	        5       U l        g N)superr   __init___loopset_waiting)selfr   	__class__s     K/root/lseg-credit/backend/venv/lib/python3.13/site-packages/pyee/asyncio.pyr   AsyncIOEventEmitter.__init__'   s    !41326
%(U    fargs.kwargsc                   ^   U" U0 UD6n[        U5      (       aN  T R                  (       a#  [        [        [        U5      T R                  S9nOA[        [        [        U5      5      nO'[        U[        5      (       a  [        [        U5      nOg U 4S jnUR                  U5        T R                  R                  U5        g ! [         a  nT R                  SU5         S nAg S nAff = f)N)r   c                    > TR                   R                  U 5        U R                  5       (       a  g U R                  5       nU(       a  TR	                  SU5        g g )Nerror)r   remove	cancelled	exceptionemit)r   excr   s     r   callback/AsyncIOEventEmitter._emit_run.<locals>.callbackE   sD    $$Q';;==!"IIgs+ r   r$   )r   r   r   r	   r   
isinstancer   add_done_callbackr   add	Exceptionr(   )r   r   r    r!   corofutr*   r)   s   `       r   	_emit_runAsyncIOEventEmitter._emit_run,   s    	#4*6*D 4  ::  -T#t_4::NC'S$8CD&))3o, !!(+MMc"9  	$IIgs##	$s   C 
C)C$$C))r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r
   strr2   __static_attributes____classcell__)r   s   @r   r   r      sU    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>rA      s0    J I B B B " 
!E#, E#r   