MCPcopy Create free account
hub / github.com/ampproject/amphtml / delayAfterDeferringToEventLoop

Function delayAfterDeferringToEventLoop

extensions/amp-sidebar/0.2/utils.js:15–25  ·  view source on GitHub ↗
(win, duration)

Source from the content-addressed store, hash-verified

13 * @return {!Promise} A Promise that resolves after the specified duration.
14 */
15export function delayAfterDeferringToEventLoop(win, duration) {
16 // TODO(spaharmi): generalize this to work outside requestAnimationFrame
17 // and move function to src/timer-impl.js
18 const timer = Services.timerFor(win);
19 // Timer.promise does not defer to event loop for 0.
20 const eventLoopDelay = 1;
21 // First, defer to the JavaScript execution loop. If we are in a
22 // requestAnimationFrame, this will place us after render. Second, wait
23 // for duration to elapse.
24 return timer.promise(eventLoopDelay).then(() => timer.promise(duration));
25}

Callers 3

carrySwipeMomentum_Method · 0.90
snapBackFromSwipe_Method · 0.90
dismissFromSwipe_Method · 0.90

Calls 2

promiseMethod · 0.80
thenMethod · 0.45

Tested by

no test coverage detected