* @private
(id: number, ack: (...args: any[]) => void)
| 313 | * @private |
| 314 | */ |
| 315 | private registerAckCallback(id: number, ack: (...args: any[]) => void): void { |
| 316 | const timeout = this.flags.timeout; |
| 317 | if (timeout === undefined) { |
| 318 | this.acks.set(id, ack); |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | const timer = setTimeout(() => { |
| 323 | debug("event with ack id %d has timed out after %d ms", id, timeout); |
| 324 | this.acks.delete(id); |
| 325 | ack.call(this, new Error("operation has timed out")); |
| 326 | }, timeout); |
| 327 | |
| 328 | this.acks.set(id, (...args) => { |
| 329 | clearTimeout(timer); |
| 330 | ack.apply(this, [null, ...args]); |
| 331 | }); |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Targets a room when broadcasting. |