Created
November 6, 2016 10:39
-
-
Save nagyadam2092/4331ed7422a315a9817b1b8aa404460b 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
magic(function*() { | |
const uri = 'http://date.jsontest.com/'; | |
const response = yield fetch(uri); | |
const date = yield response.json(); | |
const time = date.time; | |
console.log('time: ', time); | |
}); | |
function magic(generator) { | |
const iterator = generator(); | |
const iteration = iterator.next(); | |
console.log('iteration: ', iteration); | |
const promise = iteration.value; | |
promise.then(response => { | |
console.log('response: ', response); | |
const anotherIterator = iterator.next(response); | |
const anotherPromise = anotherIterator.value; | |
anotherPromise.then(date=> iterator.next(date)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment