Powerful and flexible EventEmitter implementation with advanced features.
Project description
Event Emitter
Overview
The Event Emitter (PyEventEmitter) is a powerful tool for managing event listeners and emitting events in your application. It provides a range of methods for adding, removing, and checking listeners, as well as emitting events with arguments.
Initialization
__init__(options: Optional[Dict[str, Any]] | None) -> None
Initializes a new instance of the Event Emitter class. The options
parameter is an optional dictionary containing configuration options for the Event Emitter. If provided, the captureRejections
flag is set to the value of the 'captureRejections' key in the options
dictionary. If the 'captureRejections' key is not present in the options
dictionary, or if options
is None
, the captureRejections
flag is set to False
.
events
and captureRejections
Attributes
-
events
: A dictionary storing event listeners. -
captureRejections
: A flag indicating whether the Event Emitter captures and emits rejections.
Methods
on(event_name: str, listener: Callable[..., None]) -> None
Adds a listener to the specified event.
off(event_name: str, listener: Callable[..., None]) -> None
Removes a listener from the specified event.
emit(event_name: str, *args: Any) -> self
Emits an event with the given name and arguments.
once(event_name: str, listener: Callable[..., None]) -> self
Adds a listener to the specified event that will be executed only once.
listeners(event_name: str) -> List[Callable[..., None]]
Returns a list of listeners for the specified event name.
listener_count(event_name: str) -> int
Returns the number of listeners for the specified event name.
remove_listener(event_name: str, listener: Callable[..., None]) -> self
Removes a listener from the specified event.
remove_all_listeners(event_name: Optional[str] = None) -> self
Removes all listeners for the specified event or all events if no event name is provided.
set_max_listeners(n: int) -> self
Sets the maximum number of listeners for the event emitter.
get_max_listeners() -> int
Returns the maximum number of listeners for the event emitter.
prependListener(event_name: str, listener: Callable[..., None]) -> self
Adds a listener to the beginning of the listeners array for the specified event.
prependOnceListener(event_name: str, listener: Callable[..., None]) -> self
Adds a one-time listener function to the beginning of the listeners array for the specified event.
event_names() -> List[str]
Returns a list of event names.
addAbortListener(signal: AbortSignal, resource: Callable[[str], None]) -> Disposable
Adds an abort listener to the event emitter.
captureRejection() -> bool
Gets the current setting for capturing rejection events.
defaultMaxListeners() -> int
Returns the default maximum number of listeners allowed per event.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for PyEventsEmitter-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eceb0dc879b0bcdff99b7d6a9e211f45569b32354d218f5e105866916d2e6ad0 |
|
MD5 | 68675020c109e3d1b1db4f23673b4e6a |
|
BLAKE2b-256 | 1a0b927490faf3269e658d417df153c042da3e14dda6d723718e3d432a674918 |