(chainId: symbol, typeMapping?: T)
| 513 | #resetFallbackOnReply?: Decoder["onReply"]; |
| 514 | |
| 515 | async reset<T extends TypeMapping>(chainId: symbol, typeMapping?: T) { |
| 516 | return new Promise((resolve, reject) => { |
| 517 | // overriding onReply to handle `RESET` while in `MONITOR` or PubSub mode |
| 518 | this.#resetFallbackOnReply = this.decoder.onReply; |
| 519 | this.decoder.onReply = ((reply) => { |
| 520 | if ( |
| 521 | (typeof reply === "string" && reply === "RESET") || |
| 522 | (reply instanceof Buffer && RESET.equals(reply)) |
| 523 | ) { |
| 524 | this.#resetDecoderCallbacks(); |
| 525 | this.#resetFallbackOnReply = undefined; |
| 526 | this.#pubSub.reset(); |
| 527 | |
| 528 | this.#waitingForReply.shift()!.resolve(reply); |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | this.#resetFallbackOnReply!(reply); |
| 533 | }) as Decoder["onReply"]; |
| 534 | |
| 535 | this.#toWrite.push({ |
| 536 | args: ["RESET"], |
| 537 | chainId, |
| 538 | abort: undefined, |
| 539 | timeout: undefined, |
| 540 | resolve, |
| 541 | reject, |
| 542 | channelsCounter: undefined, |
| 543 | typeMapping, |
| 544 | }); |
| 545 | }); |
| 546 | } |
| 547 | |
| 548 | isWaitingToWrite() { |
| 549 | return this.#toWrite.length > 0; |
no test coverage detected