emit-promise
Version:
Promisified socket.io acknowledgement callbacks.
17 lines • 819 B
TypeScript
/** @module emit-promise
*/
declare module "emit-promise" {
/**
* Emits an event to the socket and resolves the socket's answer in a Promise
* @async
* @function
* @param {{emit: (eventName: string, payload: ...*, callback: * => void) => void}} socket Socket object with an `emit` function
* @param {number|boolean} timeout Timeout in milliseconds, `true` for default value of 60 seconds, `false` to disable timeout and risk waiting forever
* @param {...*} payload Things to send with the event
* @returns {Promise<any>} Answer from socket
* @example
* import emitPromise from "emit-promise"
* const status = await emitPromise(socketIoServerSocket, 15000, "getStatus")
*/
export function main(timeout: number | boolean, ...payload: any[]): Promise<any>;
}