MCPcopy
hub / github.com/ampproject/amphtml / poll

Function poll

testing/iframe.js:460–483  ·  view source on GitHub ↗
(description, condition, opt_onError, opt_timeout)

Source from the content-addressed store, hash-verified

458 * @template T
459 */
460export function poll(description, condition, opt_onError, opt_timeout) {
461 return new Promise((resolve, reject) => {
462 const start = Date.now();
463 const end = opt_timeout || 1600;
464 function poll() {
465 const ret = condition();
466 if (ret) {
467 clearInterval(interval);
468 resolve(ret);
469 } else {
470 if (Date.now() - start > end) {
471 clearInterval(interval);
472 if (opt_onError) {
473 reject(opt_onError());
474 return;
475 }
476 reject(new Error('Timeout waiting for ' + description));
477 }
478 }
479 }
480 const interval = setInterval(poll, 8);
481 poll();
482 });
483}
484
485/**
486 * Polls for the given number of elements to have received layout or

Callers 15

test-errors.jsFile · 0.90
waitForOpacityFunction · 0.90
submitFormFunction · 0.90
waitForAnimationPlayFunction · 0.90
test-amp-ad-3p.jsFile · 0.90
test-amp-bind.jsFile · 0.90
listTestsFunction · 0.90
waitForDisplayChangeFunction · 0.90

Calls 4

nowMethod · 0.80
clearIntervalFunction · 0.50
resolveFunction · 0.50
setIntervalFunction · 0.50

Tested by

no test coverage detected