Last active
November 4, 2016 01:56
-
-
Save matthieu-D/b56647e6a896f32fec0aee660dffbac4 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 getIdInDb () { | |
// Simulate async Db request | |
setTimeout(function() { | |
tmp.next(2); // I return 2 as a result for my Id | |
}, 2000); | |
} | |
// Use the id returned by the yielded function | |
function getUserWithId (id) { | |
console.log('Getting user with id:', id); | |
} | |
function *doSomethingInTheDb () { | |
let id = yield getIdInDb(); | |
console.log('The id is:', id); | |
getUserWithId(id); | |
} | |
// Stock the generator | |
var tmp = doSomethingInTheDb(); | |
// Trigger the first yield | |
tmp.next(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment