
    Yh	                     p    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  \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\S\\   SS4U 4S jjjrS\S\	S	\
\S
4   S\\\4   SS4
S jrSS\S\SS4S jjrS\SS 4S jrS\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selfexecutorreturnc                 d   > [         [        U ]  5         U(       a  Xl        g [	        5       U l        g N)superr   __init__	_executorr   )r   r   	__class__s     ?/var/www/html/env/lib/python3.13/site-packages/pyee/executor.pyr   ExecutorEventEmitter.__init__1   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   r   c                    > 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_run8   sI     ..qB4B6B		!	!	 	D 	 
"	r   waitc                 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.shutdownH   s     	T*r   c                     U $ r    )r   s    r   	__enter__ExecutorEventEmitter.__enter__M   s    r   typevalue	tracebackc                 $    U R                  5         g r   )r1   )r   r7   r8   r9   s       r   __exit__ExecutorEventEmitter.__exit__P   s     	r   )r   r   )T)__name__
__module____qualname____firstlineno____doc__Selfr
   r   r   r   r   r   r	   strr-   boolr1   r5   r   r%   r   r;   __static_attributes____classcell__)r   s   @r   r   r      s     D2t 2x'9 2T 2 2 CHo S#X	
 
 +t +4 +4 +
 !7 y/2;HU	$ r   N)concurrent.futuresr   r   r   typesr   typingr   r   r	   r
   r   r   	pyee.baser   rB   __all__r   r4   r   r   <module>rL      s5    D C  = = "
!
"F< Fr   