* @private
(id: number, ack: (...args: any[]) => void)
| 406 | * @private |
| 407 | */ |
| 408 | private registerAckCallback(id: number, ack: (...args: any[]) => void): void { |
| 409 | const timeout = this.flags.timeout; |
| 410 | if (timeout === undefined) { |
| 411 | this.acks.set(id, ack); |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | const timer = setTimeout(() => { |
| 416 | debug("event with ack id %d has timed out after %d ms", id, timeout); |
| 417 | this.acks.delete(id); |
| 418 | ack.call(this, new Error("operation has timed out")); |
| 419 | }, timeout); |
| 420 | |
| 421 | this.acks.set(id, (...args) => { |
| 422 | clearTimeout(timer); |
| 423 | ack.apply(this, [null, ...args]); |
| 424 | }); |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Targets a room when broadcasting. |