Skip to content

Instantly share code, notes, and snippets.

@farskid
Last active May 21, 2019 19:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farskid/9d91f9f9b13dea58def6c3757be6c129 to your computer and use it in GitHub Desktop.
Save farskid/9d91f9f9b13dea58def6c3757be6c129 to your computer and use it in GitHub Desktop.
Concurrent, Parallel and Sequential operations using Javascript Promise.
async function concurrent() {
const fetchA = A.fetch();
const fetchB = B.fetch();
const responseA = await fetchA;
const responseB = await fetchB;
return {a: responseA, b: responseB};
}
async function parallel() {
const fetchA = A.fetch;
const fetchB = B.fetch;
const [responseA, responseB] = await Promise.all([fetchA(), fetchB()]);
return {a: responseA, b: responseB};
}
async function sequential() {
const responseA = await A.fetch();
const responseB = await B.fetch();
return {a: responseA, b: responseB};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment