(packet: any[])
| 614 | } |
| 615 | |
| 616 | override async serverSideEmit(packet: any[]) { |
| 617 | const withAck = typeof packet[packet.length - 1] === "function"; |
| 618 | |
| 619 | if (!withAck) { |
| 620 | return this.publish({ |
| 621 | type: MessageType.SERVER_SIDE_EMIT, |
| 622 | data: { |
| 623 | packet, |
| 624 | }, |
| 625 | }); |
| 626 | } |
| 627 | |
| 628 | const ack = packet.pop(); |
| 629 | const expectedResponseCount = (await this.serverCount()) - 1; |
| 630 | |
| 631 | debug( |
| 632 | '[%s] waiting for %d responses to "serverSideEmit" request', |
| 633 | this.uid, |
| 634 | expectedResponseCount, |
| 635 | ); |
| 636 | |
| 637 | if (expectedResponseCount <= 0) { |
| 638 | return ack(null, []); |
| 639 | } |
| 640 | |
| 641 | const requestId = randomId(); |
| 642 | |
| 643 | const timeout = setTimeout(() => { |
| 644 | const storedRequest = this.requests.get(requestId); |
| 645 | if (storedRequest) { |
| 646 | ack( |
| 647 | new Error( |
| 648 | `timeout reached: only ${storedRequest.current} responses received out of ${storedRequest.expected}`, |
| 649 | ), |
| 650 | storedRequest.responses, |
| 651 | ); |
| 652 | this.requests.delete(requestId); |
| 653 | } |
| 654 | }, DEFAULT_TIMEOUT); |
| 655 | |
| 656 | const storedRequest = { |
| 657 | type: MessageType.SERVER_SIDE_EMIT, |
| 658 | resolve: ack, |
| 659 | timeout, |
| 660 | current: 0, |
| 661 | expected: expectedResponseCount, |
| 662 | responses: [], |
| 663 | }; |
| 664 | this.requests.set(requestId, storedRequest); |
| 665 | |
| 666 | this.publish({ |
| 667 | type: MessageType.SERVER_SIDE_EMIT, |
| 668 | data: { |
| 669 | requestId, // the presence of this attribute defines whether an acknowledgement is needed |
| 670 | packet, |
| 671 | }, |
| 672 | }); |
| 673 | } |
nothing calls this directly
no test coverage detected