Skip to content

Instantly share code, notes, and snippets.

@1999
Last active December 18, 2015 07:09
Show Gist options
  • Save 1999/5744592 to your computer and use it in GitHub Desktop.
Save 1999/5744592 to your computer and use it in GitHub Desktop.
Игры с генераторами
var fs = require("fs");
function thread(fn) {
var gen = fn();
function next(err, res) {
var ret = gen.send(res);
if (ret.done) {
console.log("DONE")
return;
}
ret.value(next);
}
next();
}
function read(path) {
return function(done){
fs.readFile(path, "utf8", done);
}
}
thread(function *(){
var a = yield read("/Users/staypositive/sample.html");
var b = yield read(__filename);
console.log(a);
console.log(b);
});
series(function *(){
var a = yield read("/Users/staypositive/sample.html");
var b = yield read(__filename);
console.log(a);
console.log(b);
});
parallel(function *() {
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment