UNPKG

sqs-consumer

Version:

Build SQS-based Node applications without the boilerplate

32 lines (31 loc) 1.38 kB
import { EventEmitter } from "node:events"; import { Events, QueueMetadata } from "./types.js"; export declare class TypedEventEmitter extends EventEmitter { protected queueUrl?: string; /** * @param queueUrl - The URL of the SQS queue this emitter is associated with */ constructor(queueUrl?: string); /** * Trigger a listener on all emitted events * @param event The name of the event to listen to * @param listener A function to trigger when the event is emitted */ on<E extends keyof Events>(event: E, listener: (...args: [...Events[E], QueueMetadata]) => void): this; /** * Trigger a listener only once for an emitted event * @param event The name of the event to listen to * @param listener A function to trigger when the event is emitted */ once<E extends keyof Events>(event: E, listener: (...args: [...Events[E], QueueMetadata]) => void): this; /** * Emits an event with the provided arguments and adds queue metadata * @param event The name of the event to emit * @param args The arguments to pass to the event listeners * @returns {boolean} Returns true if the event had listeners, false otherwise * @example * // Inside a method: * this.emit('message_received', message); */ emit<E extends keyof Events>(event: E, ...args: Events[E]): boolean; }