Created
October 9, 2018 21:40
-
-
Save LearningNerd/0c6b077ea702f4ecbf72291ba0f82cd7 to your computer and use it in GitHub Desktop.
Just a quick example of a generator function, mostly borrowed from https://davidwalsh.name/async-generators
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
// Just a quick example of a generator function, | |
// mostly borrowed from https://davidwalsh.name/async-generators | |
function request(param) { | |
console.log("called request() with " + param); | |
makeAsyncCall( param, function(response){ | |
it.next( response ); | |
} ); | |
} | |
function makeAsyncCall(param,cb) { | |
console.log("called makeAsyncCall()"); | |
setTimeout(function(){ | |
console.log("async thingy done!!!"); | |
cb(param); | |
}, 3000); | |
} | |
function *main() { | |
let result1 = yield request( "param 1" ); | |
let result2 = yield request( "param 2 plus " + result1 ); | |
console.log( "Value of final result: " + result2 ); | |
} | |
let it = main(); | |
it.next(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment