Last active
March 4, 2021 17:54
-
-
Save syropian/097792f068eff03286e62ef5d06bb8b8 to your computer and use it in GitHub Desktop.
Lets you queue up async tasks and executes them sequentially
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
const queueTask = (() => { | |
let pending = () => Promise.resolve(); | |
const run = async (fn) => { | |
try { | |
await pending; | |
} finally { | |
return fn(); | |
} | |
}; | |
return (fn) => (pending = run(fn)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use like: