* 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>>
)
| 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. |
no test coverage detected