Skip to content

Instantly share code, notes, and snippets.

@proclaim
Last active June 23, 2016 15:42
Show Gist options
  • Save proclaim/e77f97d380ee4bd8a3108c6b4c86d65c to your computer and use it in GitHub Desktop.
Save proclaim/e77f97d380ee4bd8a3108c6b4c86d65c to your computer and use it in GitHub Desktop.
function* fetchStudentAddress() {
var studentList = yield getStudentList();
var studentInfo = yield getStudentInfo(studentList[0].id);
}
function getAddress(callback) {
var getter = fetchStudentAddress();
const go = (result) => {
if(result.done) return; // generator depleted
result.value.then((r) => {
go(getter.next(r)); // pass result to next async
})
}
go(getter.next());
}
getAddress(address => console.log(address)); // writes out address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment