| 62 | |
| 63 | // Wrapper that adds timeout to bash commands |
| 64 | function withTimeout<T>(promise: Promise<T>, timeoutMs: number, command: string): Promise<T> { |
| 65 | return new Promise((resolve, reject) => { |
| 66 | const timer = setTimeout(() => { |
| 67 | reject(new TimeoutError(command, timeoutMs)); |
| 68 | }, timeoutMs); |
| 69 | |
| 70 | promise |
| 71 | .then((result) => { |
| 72 | clearTimeout(timer); |
| 73 | resolve(result); |
| 74 | }) |
| 75 | .catch((err) => { |
| 76 | clearTimeout(timer); |
| 77 | reject(err); |
| 78 | }); |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | // Wrapper that adds timeout to just-bash exec calls |
| 83 | function createTimeoutBash(bash: Bash, timeoutMs: number) { |