(win, duration)
| 13 | * @return {!Promise} A Promise that resolves after the specified duration. |
| 14 | */ |
| 15 | export 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 | } |
no test coverage detected