-
-
Save gaurang847/a6804f916f570333e6fdf1c764c6c2f9 to your computer and use it in GitHub Desktop.
This file contains 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
//Considering getValueFromFile1, getValueFromFile2 and getValueFromFile3 | |
//all return promises | |
function* coroutine(){ //this part looks | |
let a = yield getValueFromFile1(); //very similar to | |
let b = yield getValueFromFile2(); //the synchronous | |
let sum = a + b; //equivalent | |
yield printSumToFile3(sum); | |
console.log('Success'); | |
} | |
let co = coroutine(); | |
co.next().value //getValueFromFile1() called; which returns a promise | |
.then(result => co.next(result).value) //result stored in variable 'a' and getValueFromFile2() called | |
.then(result => co.next(result).value) //result stored in variable 'b' and printSumToFile3() called | |
.then(result => co.next(result).value); //print 'Success' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment