Creates callback that can be called with payload to emit event.
```ts const callback = events.emitCallback("newMessage")
callback(message) // emits "newMessage" with message
as payload
Removes all listeners for the given event.
Subscribes listener to specified event.
Function that unsubscribe listener from the specified event
function() {
const unsubscribe = events.on("connected", () => {
console.log("event connected received")
})
unsubscribe() // listener for connected won't be called anymore
}
Subscribes to event, and when it received immediately unsubscribe.
Unsubscribe function can be called at any time.
const unsubscribe = events.once("newMessage", (message) => {
console.log(message)
})
setTimeout(() => unsubscribe(), 300) // unsubscribe from event after 300 ms
Creates promise that resolves when specified event is received.
Promise resolved with payload of the event
async function() {
const message = await events.take("messageReceived")
}
Creates promise that resolves when left event is received with payload of the event.
Promise rejects when right event is received with payload of the event.
async function() {
try {
const auth = await events.takeEither("authSuccess", "authFailure");
} catch (authError) {
console.error(authError);
}
}
Creates a promise that resolves when specified event is received.
Promise is rejected when timeout is reached.
milliseconds
Promise resolves with payload of the received event.
async function() {
try {
const message = await events.takeTimeout("messageReceived", 300);
} catch () {
console.log("Timeout reached.");
}
}
Generated using TypeDoc
Emit all listeners with payload.
Payload for event that passed to all listeners