Last active
December 18, 2015 07:09
-
-
Save 1999/5744592 to your computer and use it in GitHub Desktop.
Игры с генераторами
This file contains hidden or 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
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); | |
}); |
This file contains hidden or 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
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