(isReady: () => boolean, timeoutSec: number = 5, shouldThrow: boolean = true)
| 347 | } |
| 348 | |
| 349 | export 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) |
no test coverage detected