Last active
January 3, 2016 04:49
-
-
Save joubertnel/8411379 to your computer and use it in GitHub Desktop.
denode
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
var fs = require('fs'), | |
jspipe = require('jspipe'), | |
Pipe = jspipe.Pipe, | |
job = jspipe.job, | |
filenames = ['file1.txt', 'file2.txt', 'file3.txt']; | |
function denode(fn, args) { | |
var pipe = new Pipe(), | |
newArgs = args instanceof Array ? args : [args]; | |
newArgs.push(function(err, data) { | |
var result = err ? {err:err} : {data:data}; | |
pipe.send(result); | |
}); | |
fn.apply(fn, newArgs); | |
return pipe.get(); | |
} | |
job(function* () { | |
var msg, | |
i, | |
filedata = []; | |
for (i in filenames) { | |
msg = yield denode(fs.readFile, filenames[i]); | |
filedata[i] = msg.data ? msg.data.toString('utf8') : msg.err; | |
} | |
console.log(filedata); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment