Last active
December 12, 2017 13:45
-
-
Save ycmjason/352e9e581fe19120abd2e4c329af0a62 to your computer and use it in GitHub Desktop.
Queuing the promise!
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
const queue = (() => { | |
const promises = {}; | |
return async (name, f) => { | |
while(promises[name]) await promises[name]; | |
promises[name] = f(); | |
const res = await promises[name]; | |
promises[name] = undefined; | |
return res; | |
}; | |
})(); | |
queue('prompt', () => prompt_for_user()); | |
queue('prompt', () => prompt_for_user()); | |
queue('prompt', () => prompt_for_user()); | |
// this allow us to prompt the questions one by one |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment