API Reference¶
forgeevent.handlers.base¶
Base classes for event handlers in the forgeevent framework.
This module provides the abstract base class BaseEventHandler
,
which defines the interface for handling events.
Subclasses must implement the handle
method to define how individual events are processed.
BaseEventHandler
¶
Bases: ABC
Abstract base class for event handlers.
This class defines the interface for handling events.
Subclasses must implement the handle
method
to define how individual events are processed.
Methods¶
dispatch(events: Iterable[Event]) -> None Asynchronously dispatches a collection of events by handling each event. handle(event: Event) -> None Abstract method to handle a single event. Must be implemented by subclasses.
Source code in forgeevent/handlers/base.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
dispatch(events)
async
¶
Dispatch a collection of events by asynchronously handling each event.
Parameters¶
events : Iterable[Event] An iterable of Event objects to be handled.
Source code in forgeevent/handlers/base.py
34 35 36 37 38 39 40 41 42 43 |
|
handle(event)
abstractmethod
async
¶
Handle a single event.
Parameters¶
event : Event The event to handle.
Source code in forgeevent/handlers/base.py
45 46 47 48 49 50 51 52 53 54 55 |
|
forgeevent.handlers.local¶
Local event handler for managing and dispatching events within the application.
This module provides the LocalHandler
class, which allows registering event listeners, retrieving
registered listeners, and handling events asynchronously or synchronously.
LocalHandler
¶
Bases: BaseEventHandler
Event handler that manages event listeners and dispatches events locally.
This class allows registering listeners for specific event names and handles the execution of those listeners when an event is triggered. It supports both synchronous and asynchronous listeners.
Attributes¶
_listeners : ClassVar[dict[EventName, list[Callable[..., Any]]]] Dictionary mapping event names to lists of listener functions.
Source code in forgeevent/handlers/local.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
handle(event)
async
¶
Handle a single event.
Parameters¶
event : Event The event to handle.
Source code in forgeevent/handlers/local.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
register(event_name, listener=None)
¶
Register a listener for a specific event name, optionally as a decorator.
Parameters¶
event_name : EventName The name of the event to listen for. listener : Callable[..., Any] | None The function to register, or None if used as a decorator.
Returns¶
Callable[..., Any] The registered listener or a decorator.
Examples¶
As a decorator: @handler.register(event_name=MyEvent) def on_my_event(event): ...
As a direct call
def on_my_event(event): ... handler.register(event_name=MyEvent, listener=on_my_event)
Source code in forgeevent/handlers/local.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|