Created
March 8, 2016 15:35
-
-
Save ibigbug/557cfadbb7089b7f0b2c 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
'use strict'; | |
var fs = require('fs') | |
var read = function(name) { | |
return function(cb) { | |
fs.readFile(name, {encoding: 'utf-8'}, cb) | |
} | |
} | |
function wrap(gen) { | |
let g = gen() | |
iter(g.next()) | |
function iter(n) { | |
if (!n.done) { | |
let val = n.value | |
if (typeof val === 'function') { | |
val(function(err, data) { | |
iter(g.next(data)) | |
}) | |
} else { | |
g.next(val) | |
} | |
} else { | |
g.next(n.value) | |
} | |
} | |
} | |
wrap(function*() { | |
console.log(yield read('./GLOSSARY.md')) | |
console.log(123) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment