Skip to content

Instantly share code, notes, and snippets.

@nagyadam2092
Created November 6, 2016 10:39
Show Gist options
  • Save nagyadam2092/4331ed7422a315a9817b1b8aa404460b to your computer and use it in GitHub Desktop.
Save nagyadam2092/4331ed7422a315a9817b1b8aa404460b to your computer and use it in GitHub Desktop.
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