Events¶
-
class
Event
()¶ A structure for events fired in various parts of the toolkit.
Arguments: - name (string) – the event’s name.
- data (string) – the event’s data. Optional.
-
class
Event
() Lightweight wrapper around
EventEmitter()
for working better with Q promises and the toolkit’sEvent()
objects.
-
Eventable.
emit
(event)¶ Emits the given event and returns a promise that will be fulfilled once each listener is done. This allows listeners to return promises.
Arguments: - event (Event) – the event to emit.
-
static
setup
()¶ Shortcut for emitting a setup event for the instance (since this is done quite often). See
SetupEvent()
.
-
static
teardown
()¶ Shortcut for emitting a teardown event for the instance. See
TeardownEvent()
.
-
Eventable.once.
resolved
(event_name)¶ Returns a promise that will be fulfilled once the event has been emitted. Since a promise can only be fulfilled once, the event listener is removed after the event is emitted. Useful for testing events.
Arguments: - event_name (string) – the event to listen for.
-
Eventable.
teardown_listeners
()¶ Removes all event listeners, with the following exception: listeners for
TeardownEvent()
s get rebound usingEventable.once()
, regardless of whether they were orginally bound usingEventable.on()
orEventable.once()
. This allows us to remove all event listeners for instances ofEventable()
, while still allowing other entities to know when the teardown of the entity has completed.Not that it is up to the caller to emit the
TeardownEvent()
to clear the listeners.
-
class
SetupEvent
(instance)¶ Emitted when an instance of something has been constructed.
Arguments: - instance (object) – the constructed instance.
-
class
TeardownEvent
(instance)¶ Emitted when an instance of something has completed the tasks it needs to complete before it can be safely disposed of.
Arguments: - instance (object) – the instance.