| 126 | |
| 127 | /// Waits for all the provided promises, but throws if the debugger terminates before they complete. |
| 128 | export function waitAllThrowIfTerminates(dc: DartDebugClient, ...promises: Array<Promise<any>>) { |
| 129 | let didCompleteSuccessfully = false; |
| 130 | return Promise.race([ |
| 131 | new Promise<void>(async (resolve, reject) => { |
| 132 | await dc.waitForEvent("terminated", "waitAllThrowIfTerminates", 180000); |
| 133 | // Wait a small amount to allow other awaited tasks to complete. |
| 134 | setTimeout(() => { |
| 135 | if (didCompleteSuccessfully) { |
| 136 | resolve(); |
| 137 | return; |
| 138 | } |
| 139 | reject(Error("Terminated while waiting for other promises!")); |
| 140 | }, 500); |
| 141 | }), |
| 142 | Promise.all(promises).then(() => didCompleteSuccessfully = true), |
| 143 | ]); |
| 144 | } |
| 145 | |
| 146 | export function ensureVariable(variables: DebugProtocol.Variable[], evaluateName: string | undefined, name: string, value: string | { starts?: string, ends?: string }) { |
| 147 | assert.ok(variables?.length, "No variables given to search"); |