| 249 | }, |
| 250 | }; |
| 251 | return new AskStream(source, this.config.timeoutMs); |
| 252 | } |
| 253 | |
| 254 | async close(): Promise<void> { |
| 255 | if (this.#closed) return; |
| 256 | this.#closed = true; |
| 257 | const child = this.#child; |
| 258 | if (!child) return; |
| 259 | this.#stdin?.end(); |
| 260 | if (typeof child.once === "function" && typeof child.kill === "function") { |
| 261 | await new Promise<void>((resolve) => { |
| 262 | let finished = false; |
| 263 | const done = () => { |
| 264 | if (!finished) { |
| 265 | finished = true; |
| 266 | resolve(); |
| 267 | } |
| 268 | }; |
| 269 | child.once("exit", done); |
| 270 | setTimeout(() => { |
| 271 | if (!finished) child.kill(); |
| 272 | done(); |
| 273 | }, 5000); |
| 274 | }); |
| 275 | } |
| 276 | this.#failAll(new ConnectionError("client closed", "transport")); |
| 277 | } |
| 278 | } |