
    5j	                     l    S SK JrJrJr  S SKJr  S SKJrJrJ	r	J
r
JrJr  S SKJr  S/r " S S\5      rg)    )ExecutorFutureThreadPoolExecutor)TracebackType)AnyCallableDictOptionalTupleType)EventEmitterExecutorEventEmitterc            	          ^  \ 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S\SS4S jjrSS jrS\\   S\S\S\\   4S jrSrU =r$ )r      a  An event emitter class which runs handlers in a `concurrent.futures`
executor.

By default, this class creates a default `ThreadPoolExecutor`, but
a custom executor may also be passed in explicitly to, for instance,
use a `ProcessPoolExecutor` instead.

This class runs all emitted events on the configured executor. Errors
captured by the resulting Future are automatically emitted on the
`error` event. This is unlike the EventEmitter, which have no error
handling.

The underlying executor may be shut down by calling the `shutdown`
method. Alternately you can treat the event emitter as a context manager:

```py
with ExecutorEventEmitter() as ee:
    # Underlying executor open

    @ee.on('data')
    def handler(data):
        print(data)

    ee.emit('event')

# Underlying executor closed
```

Since the function call is scheduled on an executor, emit is always
non-blocking.

No effort is made to ensure thread safety, beyond using an executor.
Nexecutorc                 d   > [         [        U ]  5         U(       a  Xl        g [	        5       U l        g N)superr   __init__	_executorr   )selfr   	__class__s     L/root/lseg-credit/backend/venv/lib/python3.13/site-packages/pyee/executor.pyr   ExecutorEventEmitter.__init__/   s#    "D24'/N/1DN    fargs.kwargsc                    ^  T R                   R                  " U/UQ70 UD6nUR                  S[        SS 4U 4S jj5       ng )Nr   returnc                    > U R                  5       n[        U[        5      (       a  TR                  SU5        g Ub  Ueg )Nerror)	exception
isinstance	Exceptionemit)r   excr   s     r   	_callback1ExecutorEventEmitter._emit_run.<locals>._callback>   s8    +,;;=C#y))		'3'	 !r   )r   submitadd_done_callbackr   )r   r   r   r   futurer(   s   `     r   	_emit_runExecutorEventEmitter._emit_run6   sI     ..qB4B6B		!	!	 	D 	 
"	r   waitr    c                 6    U R                   R                  US9  g)z)Call `shutdown` on the internal executor.)r/   N)r   shutdown)r   r/   s     r   r1   ExecutorEventEmitter.shutdownF   s     	T*r   c                     U $ r    )r   s    r   	__enter__ExecutorEventEmitter.__enter__K   s    r   typevalue	tracebackc                 $    U R                  5         g r   )r1   )r   r7   r8   r9   s       r   __exit__ExecutorEventEmitter.__exit__N   s     	r   )r   r   )T)r    r   )__name__
__module____qualname____firstlineno____doc__r
   r   r   r   r   r   r	   strr-   boolr1   r5   r   r%   r   r;   __static_attributes____classcell__)r   s   @r   r   r      s     D2(!3 2 2 CHo S#X	 +T +T +
O,5BO	$ r   N)concurrent.futuresr   r   r   typesr   typingr   r   r	   r
   r   r   	pyee.baser   __all__r   r4   r   r   <module>rK      s0    D C  = = "!
"E< Er   