Skip to content

Instantly share code, notes, and snippets.

@ycmjason
Last active December 12, 2017 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycmjason/352e9e581fe19120abd2e4c329af0a62 to your computer and use it in GitHub Desktop.
Save ycmjason/352e9e581fe19120abd2e4c329af0a62 to your computer and use it in GitHub Desktop.
Queuing the promise!
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