MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / pollLifecycle

Function pollLifecycle

scripts/run-javascript-lifecycle-tests.mjs:316–337  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

314 * is reported promptly instead of running out the full timeout.
315 */
316async 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
339function summarise(results) {
340 console.log('');

Callers 1

runBundleFunction · 0.85

Calls 3

evaluateMethod · 0.65
nowMethod · 0.45
stringifyMethod · 0.45

Tested by

no test coverage detected