Skip to content

Instantly share code, notes, and snippets.

@myobie
Last active May 6, 2020 19:14
Show Gist options
  • Save myobie/28436695247bb09888da4f2a0e653d15 to your computer and use it in GitHub Desktop.
Save myobie/28436695247bb09888da4f2a0e653d15 to your computer and use it in GitHub Desktop.
Do some work next time the event loop is free
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