-
Notifications
You must be signed in to change notification settings - Fork 144
Emitter
Implements an asynchronous event emitter where callbacks can be subscribed to specific named events. When events are emitted, the callbacks are called in the order that they were originally registered.
Parameter | Type | Optional |
---|---|---|
name | string | |
... | * | ✔ |
Emits the named event and a variable number of arguments to pass to the event callbacks.
This method only operates on data in memory.
Returns: nil
Parameter | Type |
---|---|
name | string |
Returns the number of callbacks registered to the named event.
This method only operates on data in memory.
Returns: number
Parameter | Type |
---|---|
name | string |
Returns an iterator for all callbacks registered to the named event.
This method only operates on data in memory.
Returns: function
Parameter | Type |
---|---|
name | string |
fn | function |
Subscribes a callback to be called every time the named event is emitted. Callbacks registered with this method will automatically be wrapped as a new coroutine when they are called. Returns the original callback for convenience.
This method only operates on data in memory.
Returns: function
Parameter | Type |
---|---|
name | string |
fn | function |
Subscribes a callback to be called every time the named event is emitted. Callbacks registered with this method are not automatically wrapped as a coroutine. Returns the original callback for convenience.
This method only operates on data in memory.
Returns: function
Parameter | Type |
---|---|
name | string |
fn | function |
Subscribes a callback to be called only the first time this event is emitted. Callbacks registered with this method will automatically be wrapped as a new coroutine when they are called. Returns the original callback for convenience.
This method only operates on data in memory.
Returns: function
Parameter | Type |
---|---|
name | string |
fn | function |
Subscribes a callback to be called only the first time this event is emitted. Callbacks registered with this method are not automatically wrapped as a coroutine. Returns the original callback for convenience.
This method only operates on data in memory.
Returns: function
Parameter | Type |
---|---|
name | string/nil |
Unregisters all callbacks for the emitter. If a name is passed, then only callbacks for that specific event are unregistered.
This method only operates on data in memory.
Returns: nil
Parameter | Type |
---|---|
name | string |
fn | function |
Unregisters all instances of the callback from the named event.
This method only operates on data in memory.
Returns: nil
Parameter | Type | Optional |
---|---|---|
name | string | |
timeout | number | ✔ |
predicate | function | ✔ |
When called inside of a coroutine, this will yield the coroutine until the named event is emitted. If a timeout (in milliseconds) is provided, the function will return after the time expires, regardless of whether the event is emitted, and false
will be returned; otherwise, true
is returned. If a predicate is provided, events that do not pass the predicate will be ignored.
This method only operates on data in memory.
Returns: boolean, ...