MCPcopy
hub / github.com/socketio/socket.io / emitWithAck

Method emitWithAck

packages/socket.io/lib/socket.ts:294–310  ·  view source on GitHub ↗

* Emits an event and waits for an acknowledgement * * @example * io.on("connection", async (socket) => { * // without timeout * const response = await socket.emitWithAck("hello", "world"); * * // with a specific timeout * try { * const response = await socket.t

(
    ev: Ev,
    ...args: AllButLast<EventParams<EmitEvents, Ev>>
  )

Source from the content-addressed store, hash-verified

292 * @return a Promise that will be fulfilled when the client acknowledges the event
293 */
294 public emitWithAck<Ev extends EventNamesWithAck<EmitEvents>>(
295 ev: Ev,
296 ...args: AllButLast<EventParams<EmitEvents, Ev>>
297 ): Promise<FirstNonErrorArg<Last<EventParams<EmitEvents, Ev>>>> {
298 // the timeout flag is optional
299 const withErr = this.flags.timeout !== undefined;
300 return new Promise((resolve, reject) => {
301 args.push((arg1, arg2) => {
302 if (withErr) {
303 return arg1 ? reject(arg1) : resolve(arg2);
304 } else {
305 return resolve(arg1);
306 }
307 });
308 this.emit(ev, ...(args as any[] as EventParams<EmitEvents, Ev>));
309 });
310 }
311
312 /**
313 * @private

Callers 4

messaging-many.tsFile · 0.45
socket.tsFile · 0.45
socket-timeout.tsFile · 0.45

Calls 1

emitMethod · 0.95

Tested by

no test coverage detected