Last active
April 28, 2016 21:56
-
-
Save daniel-j-h/dd957c04c3b49b1604ccbb100ba85dd9 to your computer and use it in GitHub Desktop.
ES6 untangling callback 🍝
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
'use strict'; | |
const fs = require('fs'); | |
function spawn(generator) { | |
let it = generator(function (err, data) { | |
if (err) it.throw(err); | |
return it.next(data); | |
}); | |
it.next(); | |
} | |
function main() { | |
spawn(function* (resume) { | |
let content = yield fs.readFile(__filename, resume); | |
yield fs.writeFile(__dirname + '/dup.js', content, resume); | |
}); | |
} | |
if (require.main === module) { main(); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment