Last active
May 6, 2020 19:14
-
-
Save myobie/28436695247bb09888da4f2a0e653d15 to your computer and use it in GitHub Desktop.
Do some work next time the event loop is free
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function nextTick<O> (cb: () => O | Promise<O>): Promise<O> { | |
| return new Promise((resolve, reject) => { | |
| requestAnimationFrame(() => { | |
| Promise.resolve(cb()) | |
| .then(value => resolve(value)) | |
| .catch(e => reject(e)) | |
| }) | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment