|
| None | __init__ (Self self, Optional[Executor] executor=None) |
| |
| None | shutdown (Self self, bool wait=True) |
| |
|
"ExecutorEventEmitter" | __enter__ (Self self) |
| |
|
Optional[bool] | __exit__ (Self self, Type[Exception] type, Exception value, TracebackType traceback) |
| |
|
Mapping[str, Any] | __getstate__ (Self self) |
| |
|
None | __setstate__ (Self self, Mapping[str, Any] state) |
| |
|
Callable[[Handler], Handler] | on (Self self, str event) |
| |
|
Handler | on (Self self, str event, Handler f) |
| |
| Union[Handler, Callable[[Handler], Handler]] | on (Self self, str event, Optional[Handler] f=None) |
| |
| Callable[[Handler], Handler] | listens_to (Self self, str event) |
| |
| Handler | add_listener (Self self, str event, Handler f) |
| |
| Set[str] | event_names (Self self) |
| |
| bool | emit (Self self, str event, *Any args, **Any kwargs) |
| |
| Callable | once (Self self, str event, Optional[Callable] f=None) |
| |
| None | remove_listener (Self self, str event, Callable f) |
| |
| None | remove_all_listeners (Self self, Optional[str] event=None) |
| |
| List[Callable] | listeners (Self self, str event) |
| |
|
| None | _emit_run (Self self, Callable f, Tuple[Any,...] args, Dict[str, Any] kwargs) |
| |
|
| _add_event_handler (Self self, str event, Callable k, Callable v) |
| |
|
None | _emit_handle_potential_error (Self self, str event, Any error) |
| |
|
bool | _call_handlers (Self self, str event, Tuple[Any,...] args, Dict[str, Any] kwargs) |
| |
| None | _remove_listener (Self self, str event, Callable f) |
| |
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.