|
| None | __init__ (Self self) |
| |
|
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) |
| |
| None | _emit_handle_potential_error (Self self, str event, Any error) |
| |
|
| _add_event_handler (Self self, str event, Callable k, Callable v) |
| |
|
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 can run twisted coroutines and handle
returned Deferreds, in addition to synchronous blocking functions. For
example:
```py
@ee.on('event')
@inlineCallbacks
def async_handler(*args, **kwargs):
yield returns_a_deferred()
```
or:
```py
@ee.on('event')
async def async_handler(*args, **kwargs):
await returns_a_deferred()
```
When async handlers fail, Failures are first emitted on the `failure`
event. If there are no `failure` handlers, the Failure's associated
exception is then emitted on the `error` event. If there are no `error`
handlers, the exception is raised. For consistency, when handlers raise
errors synchronously, they're captured, wrapped in a Failure and treated
as an async failure. This is unlike the behavior of EventEmitter,
which have no special error handling.
For twisted 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.
Similar behavior occurs for "sync" functions which return Deferreds.