Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
pyee.trio.TrioEventEmitter Class Reference
Inheritance diagram for pyee.trio.TrioEventEmitter:
Inheritance graph
[legend]
Collaboration diagram for pyee.trio.TrioEventEmitter:
Collaboration graph
[legend]

Public Member Functions

 __init__ (Self self, Optional[Nursery] nursery=None, Optional["AbstractAsyncContextManager[trio.Nursery]"] manager=None)
 
AsyncGenerator["TrioEventEmitter", None] context (Self self)
 
"TrioEventEmitter" __aenter__ (Self self)
 
Optional[bool] __aexit__ (Self self, Optional[Type[BaseException]] type, Optional[BaseException] value, Optional[TracebackType] traceback)
 
- Public Member Functions inherited from pyee.base.EventEmitter
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)
 

Protected Member Functions

Callable[[], Awaitable[None]] _async_runner (Self self, Callable f, Tuple[Any,...] args, Dict[str, Any] kwargs)
 
None _emit_run (Self self, Callable f, Tuple[Any,...] args, Dict[str, Any] kwargs)
 
- Protected Member Functions inherited from pyee.base.EventEmitter
 _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)
 

Protected Attributes

 _nursery
 
 _manager
 
 _context
 
- Protected Attributes inherited from pyee.base.EventEmitter
 _lock
 
 _events
 

Detailed Description

An event emitter class which can run trio tasks in a trio nursery.

By default, this class will lazily create both a nursery manager (the
object returned from `trio.open_nursery()` and a nursery (the object
yielded by using the nursery manager as an async context manager). It is
also possible to supply an existing nursery manager via the `manager`
argument, or an existing nursery via the `nursery` argument.

Instances of TrioEventEmitter are themselves async context managers, so
that they may manage the lifecycle of the underlying trio nursery. For
example, typical usage of this library may look something like this::

```py
async with TrioEventEmitter() as ee:
    # Underlying nursery is instantiated and ready to go
    @ee.on('data')
    async def handler(data):
        print(data)

    ee.emit('event')

# Underlying nursery and manager have been cleaned up
```

Unlike the case with the EventEmitter, all exceptions raised by event
handlers are automatically emitted on the `error` event. This is
important for trio coroutines specifically but is also handled for
synchronous functions for consistency.

For trio coroutine event handlers, calling emit is non-blocking. In other
words, you should not attempt to await emit; the coroutine is scheduled
in a fire-and-forget fashion.

Constructor & Destructor Documentation

◆ __init__()

pyee.trio.TrioEventEmitter.__init__ ( Self  self,
Optional[Nursery]   nursery = None,
Optional["AbstractAsyncContextManager[trio.Nursery]"]   manager = None 
)

Reimplemented from pyee.base.EventEmitter.

Member Function Documentation

◆ _emit_run()

None pyee.trio.TrioEventEmitter._emit_run ( Self  self,
Callable  f,
Tuple[Any, ...]  args,
Dict[str, Any]  kwargs 
)
protected

Reimplemented from pyee.base.EventEmitter.

◆ context()

AsyncGenerator["TrioEventEmitter", None] pyee.trio.TrioEventEmitter.context ( Self  self)
Returns an async contextmanager which manages the underlying
nursery to the EventEmitter. The `TrioEventEmitter`'s
async context management methods are implemented using this
function, but it may also be used directly for clarity.

The documentation for this class was generated from the following file: