| 641 | } |
| 642 | |
| 643 | private setSocketTimeout() { |
| 644 | this.socketTimeoutTimer = setTimeout(() => { |
| 645 | this.stream.destroy( |
| 646 | new Error( |
| 647 | `Socket timeout. Expecting data, but didn't receive any in ${this.options.socketTimeout}ms.` |
| 648 | ) |
| 649 | ); |
| 650 | this.socketTimeoutTimer = undefined; |
| 651 | }, this.options.socketTimeout); |
| 652 | |
| 653 | // this handler must run after the "data" handler in "DataHandler" |
| 654 | // so that `this.commandQueue.length` will be updated |
| 655 | this.stream.once("data", () => { |
| 656 | clearTimeout(this.socketTimeoutTimer); |
| 657 | this.socketTimeoutTimer = undefined; |
| 658 | if (this.commandQueue.length === 0) return; |
| 659 | this.setSocketTimeout(); |
| 660 | }); |
| 661 | } |
| 662 | |
| 663 | scanStream(options?: ScanStreamOptions) { |
| 664 | return this.createScanStream("scan", { options }); |