( timeoutMs: number | undefined, abortSignal?: AbortSignal )
| 267 | } |
| 268 | |
| 269 | function createAbortController( |
| 270 | timeoutMs: number | undefined, |
| 271 | abortSignal?: AbortSignal |
| 272 | ): { signal: AbortSignal; dispose: () => void; didTimeout: () => boolean } { |
| 273 | const controller = new AbortController(); |
| 274 | let timedOut = false; |
| 275 | |
| 276 | const onAbort = () => controller.abort(); |
| 277 | if (abortSignal) { |
| 278 | if (abortSignal.aborted) { |
| 279 | controller.abort(); |
| 280 | } else { |
| 281 | abortSignal.addEventListener("abort", onAbort, { once: true }); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | const timeoutHandle = |
| 286 | timeoutMs === undefined |
| 287 | ? undefined |
| 288 | : setTimeout(() => { |
| 289 | timedOut = true; |
| 290 | controller.abort(); |
| 291 | }, timeoutMs); |
| 292 | |
| 293 | return { |
| 294 | signal: controller.signal, |
| 295 | didTimeout: () => timedOut, |
| 296 | dispose: () => { |
| 297 | if (timeoutHandle) { |
| 298 | clearTimeout(timeoutHandle); |
| 299 | } |
| 300 | abortSignal?.removeEventListener("abort", onAbort); |
| 301 | }, |
| 302 | }; |
| 303 | } |
| 304 | async function waitForProcessExit(proc: ChildProcess): Promise<number> { |
| 305 | // Callers often consume stdout before awaiting the process. Tiny git helpers |
| 306 | // can close in that window, so make the helper safe even when subscribed late. |
no test coverage detected