* Poll the page for ``cn1Initialized`` and ``cn1Started`` flags * (set by ParparVMBootstrap.setInitialized / setStarted at the end * of ``Lifecycle.init`` and ``Lifecycle.start`` respectively). A * ``__parparError`` short-circuits the wait so a runtime exception * is reported promptly instead of
(page, timeoutSeconds)
| 314 | * is reported promptly instead of running out the full timeout. |
| 315 | */ |
| 316 | async function pollLifecycle(page, timeoutSeconds) { |
| 317 | const deadline = Date.now() + timeoutSeconds * 1000; |
| 318 | let cn1Initialized = false; |
| 319 | let cn1Started = false; |
| 320 | let parparError = null; |
| 321 | |
| 322 | while (Date.now() < deadline) { |
| 323 | const state = await page.evaluate(() => ({ |
| 324 | initialized: !!window.cn1Initialized, |
| 325 | started: !!window.cn1Started, |
| 326 | error: window.__parparError ? JSON.stringify(window.__parparError) : '' |
| 327 | })); |
| 328 | if (state.initialized) cn1Initialized = true; |
| 329 | if (state.started) cn1Started = true; |
| 330 | if (state.error) parparError = state.error; |
| 331 | if (cn1Started || parparError) { |
| 332 | break; |
| 333 | } |
| 334 | await new Promise(r => setTimeout(r, 500)); |
| 335 | } |
| 336 | return { cn1Initialized, cn1Started, parparError }; |
| 337 | } |
| 338 | |
| 339 | function summarise(results) { |
| 340 | console.log(''); |