Last active
January 28, 2024 04:40
-
-
Save danielbushman/fe81d4e4896135fc99394d139425db12 to your computer and use it in GitHub Desktop.
Timing callbacks adapted to promises
This file contains 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
// usage: await timeout(1000); | |
export const timeout = (timeout = 100) => | |
new Promise(resolve => window.setTimeout(resolve, timeout)); | |
// usage: await animationFrame(); | |
export const animationFrame = () => | |
new Promise(resolve => window.requestAnimationFrame(resolve)); | |
// usage: await idle(); | |
export const idle = () => | |
new Promise(resolve => window.requestIdleCallback(resolve)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment