-
-
Save bitfishxyz/2f8b298244eecb4a276efb5a506b946e 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
function* testG() { | |
// await is translated as yield | |
const data = yield getData() | |
console.log('data: ', data); | |
const data2 = yield getData() | |
console.log('data2: ', data2); | |
return 'success' | |
} | |
var gen = testG() | |
var dataPromise = gen.next() | |
dataPromise.then((value1) => { | |
// Pass the obtained value of data1 to data2 through the next function | |
var data2Promise = gen.next(value1) | |
console.log('data: ', data); | |
data2Promise.then((value2) => { | |
gen.next(value2) | |
console.log('data2: ', data2); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment