Skip to content

Instantly share code, notes, and snippets.

@bunnyhawk
Created November 7, 2020 16:08
Show Gist options
  • Save bunnyhawk/b226b19f1702163cd44678689fbbfc0c to your computer and use it in GitHub Desktop.
Save bunnyhawk/b226b19f1702163cd44678689fbbfc0c to your computer and use it in GitHub Desktop.
const getUser = (email) => fetch(`/api/${email}`).then(res => res.json());
const promiseQueue = (values, func) => {
const reducer = (promises, value) =>
promises.then((promise) => func(value).then(res => promise.push(res) && res));
return values.reduce(reducer, Promise.result([]));
};
promiseQueue(["test@example.com", "another@example.com", "thirdOne@example.com"], getUser);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment