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

Method emitWithAck

packages/socket.io-client/lib/socket.ts:510–522  ·  view source on GitHub ↗

* Emits an event and waits for an acknowledgement * * @example * // without timeout * const response = await socket.emitWithAck("hello", "world"); * * // with a specific timeout * try { * const response = await socket.timeout(1000).emitWithAck("hello", "world"); * } catc

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

Source from the content-addressed store, hash-verified

508 * @return a Promise that will be fulfilled when the server acknowledges the event
509 */
510 public emitWithAck<Ev extends EventNames<EmitEvents>>(
511 ev: Ev,
512 ...args: AllButLast<EventParams<EmitEvents, Ev>>
513 ): Promise<FirstArg<Last<EventParams<EmitEvents, Ev>>>> {
514 return new Promise((resolve, reject) => {
515 const fn = (arg1, arg2) => {
516 return arg1 ? reject(arg1) : resolve(arg2);
517 };
518 fn.withError = true;
519 args.push(fn);
520 this.emit(ev, ...(args as any[] as EventParams<EmitEvents, Ev>));
521 });
522 }
523
524 /**
525 * Add the packet to the queue.

Callers 3

socket.tsFile · 0.45
cluster-adapter.tsFile · 0.45

Calls 1

emitMethod · 0.95

Tested by

no test coverage detected