Skip to content

Instantly share code, notes, and snippets.

@ibigbug
Created March 8, 2016 15:35
Show Gist options
  • Save ibigbug/557cfadbb7089b7f0b2c to your computer and use it in GitHub Desktop.
Save ibigbug/557cfadbb7089b7f0b2c to your computer and use it in GitHub Desktop.
'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