| 153 | } |
| 154 | |
| 155 | async run() { |
| 156 | this.killChild(); |
| 157 | |
| 158 | const { 0: child, 1: port, 2: host } = await this._runScript(); |
| 159 | this.child = child; |
| 160 | |
| 161 | this.print(`connecting to ${host}:${port} ..`, false); |
| 162 | for (let attempt = 0; attempt < 5; attempt++) { |
| 163 | debuglog('connection attempt #%d', attempt); |
| 164 | this.stdout.write('.'); |
| 165 | try { |
| 166 | await this.client.connect(port, host); |
| 167 | debuglog('connection established'); |
| 168 | this.stdout.write(' ok\n'); |
| 169 | return; |
| 170 | } catch (error) { |
| 171 | debuglog('connect failed', error); |
| 172 | await pSetTimeout(1000); |
| 173 | } |
| 174 | } |
| 175 | this.stdout.write(' failed to connect, please retry\n'); |
| 176 | process.exit(kGenericUserError); |
| 177 | } |
| 178 | |
| 179 | clearLine() { |
| 180 | if (this.stdout.isTTY) { |