Commit ad9e5564 authored by David Votrubec's avatar David Votrubec

updated Readme

parent df2f005a
......@@ -11,4 +11,6 @@ Feel free to fork and experiment, but please provide a link to the original arti
- install grunt-cli with global flag
- run npm install
- run grunt
- run `node es6\file-name.js` to see what it does
- TODO: maybe??
- grunt task will compile code inside es6 folder into es5 folder which is runnable in browser (provided it has the regenerator runtime available)
\ No newline at end of file
......@@ -2,6 +2,7 @@
// Error is thrown into the generator
// and caught outside of it
function *foo() { }
const it1 = foo();
try {
it1.throw( "Oops!" );
......@@ -16,6 +17,7 @@ catch (err) {
function *errorFoo(){
throw new Error('error was thrown inside the generator');
}
const it2 = errorFoo();
try {
it2.next();
......
function run (genFn) {
/**
* The runner function repeatedly calls the supplied generator function
* until all yields are exhausted.
*/
export default function run (/*iterator fn*/ genFn) {
var gen = genFn(); // [1]
next(); // [2]
......
import run from '03-run-function';
function loadArticle(articleId) {
const promise = new Promise(function(resolve, reject) {
setTimeout(function() {
console.log("successfully resolving articleId", articleId);
resolve();
}, 1000);
setTimeout(function() {
console.log("rejecting the promise articleId", articleId);
reject();
}, 2000);
});
return promise;
}
run(function*(){
const articleId = '1234a';
try {
const article = yield loadArticle(articleId);
// When article is loaded, load comments
//const comments = yield loadComments(articleId);
// When comments are loaded, load article's author
//const author = yield loadAuthor(article.authorId);
// in real life you would probably run all 3 request in parallel
// but you get the idea <img draggable="false" class="emoji" alt="🙂" src="https://s.w.org/images/core/emoji/72x72/1f642.png">
}
catch (err) {
console.log('error loading', err);
alert('Error loading article');
}
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment