MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / waitUntilReady

Function waitUntilReady

apps/automated/src/tk-unit.ts:349–377  ·  view source on GitHub ↗
(isReady: () => boolean, timeoutSec: number = 5, shouldThrow: boolean = true)

Source from the content-addressed store, hash-verified

347}
348
349export function waitUntilReady(isReady: () => boolean, timeoutSec: number = 5, shouldThrow: boolean = true) {
350 if (!isReady) {
351 return;
352 }
353
354 if (__APPLE__) {
355 const timeoutMs = timeoutSec * 1000;
356 let totalWaitTime = 0;
357 while (true) {
358 const begin = time();
359 const currentRunLoop = NSRunLoop.currentRunLoop;
360 currentRunLoop.limitDateForMode(currentRunLoop.currentMode);
361 if (isReady()) {
362 break;
363 }
364
365 totalWaitTime += time() - begin;
366 if (totalWaitTime >= timeoutMs) {
367 if (shouldThrow) {
368 throw new Error('waitUntilReady Timeout.');
369 } else {
370 break;
371 }
372 }
373 }
374 } else {
375 doModalAndroid(isReady, timeoutSec, shouldThrow);
376 }
377}
378
379// Setup for the Android modal loop implementation
380// TODO: If these platform-specific implementations continue to grow, think of per-platform separation (TKUnit.android)

Callers 1

waitFunction · 0.85

Calls 3

doModalAndroidFunction · 0.85
timeFunction · 0.70
isReadyFunction · 0.50

Tested by

no test coverage detected