Last active
May 21, 2019 19:11
-
-
Save farskid/9d91f9f9b13dea58def6c3757be6c129 to your computer and use it in GitHub Desktop.
Concurrent, Parallel and Sequential operations using Javascript 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
async function concurrent() { | |
const fetchA = A.fetch(); | |
const fetchB = B.fetch(); | |
const responseA = await fetchA; | |
const responseB = await fetchB; | |
return {a: responseA, b: responseB}; | |
} |
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
async function parallel() { | |
const fetchA = A.fetch; | |
const fetchB = B.fetch; | |
const [responseA, responseB] = await Promise.all([fetchA(), fetchB()]); | |
return {a: responseA, b: responseB}; | |
} |
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
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