Skip to content

Instantly share code, notes, and snippets.

@bitfishxyz
Created May 4, 2020 08:30
Show Gist options
  • Save bitfishxyz/2f8b298244eecb4a276efb5a506b946e to your computer and use it in GitHub Desktop.
Save bitfishxyz/2f8b298244eecb4a276efb5a506b946e to your computer and use it in GitHub Desktop.
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