|
| None | __init__ (Self self, Optional[AbstractEventLoop] loop=None) |
| |
| bool | emit (Self self, str event, *Any args, **Any kwargs) |
| |
| None | wait_for_complete (Self self) |
| |
| None | cancel (Self self) |
| |
| bool | complete (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) |
| |
| 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 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.
| bool pyee.asyncio.AsyncIOEventEmitter.complete |
( |
Self |
self | ) |
|
When true, there are no pending tasks, and execution is complete.
For example:
```py
@ee.on('event')
async def async_handler(*args, **kwargs):
await returns_a_future()
# Triggers execution of async_handler
ee.emit('data', '00101001')
# async_handler is still running, so this prints False
print(ee.complete)
await ee.wait_for_complete()
# async_handler has completed execution, so this prints True
print(ee.complete)
```
| bool pyee.asyncio.AsyncIOEventEmitter.emit |
( |
Self |
self, |
|
|
str |
event, |
|
|
*Any |
args, |
|
|
**Any |
kwargs |
|
) |
| |
Emit `event`, passing `*args` and `**kwargs` to each attached
function or coroutine. Returns `True` if any functions are attached to
`event`; otherwise returns `False`.
Example:
```py
ee.emit('data', '00101001')
```
Assuming `data` is an attached function, this will call
`data('00101001')'`.
When executing coroutine handlers, their respective futures will be
stored in a "waiting" state. These futures may be waited on or
canceled with `wait_for_complete` and `cancel`, respectively; and
their status may be checked via the `complete` property.
Reimplemented from pyee.base.EventEmitter.