Last active
June 23, 2016 15:42
-
-
Save proclaim/e77f97d380ee4bd8a3108c6b4c86d65c 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* 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