Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemorton committed May 26, 2011
0 parents commit 2df2dd4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions async-compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var fs = require('fs');

function asyncArray(arr, doSomething, onComplete) {
var finalArray = [];

function finished() {
if (finalArray.length === arr.length) {
onComplete(finalArray);
}
}

for (i in arr) {
doSomething(arr[i], function (arrItem) {
finalArray.push(arrItem);
finished();
});
}
}

function resolvePaths(pathArray, onComplete) {
asyncArray(
pathArray,
function (path, handle) {
fs.realpath(path, function (err, resolvedPath) {
handle(resolvedPath);
});
},
onComplete
);
}

function concatFiles(fileArray, onComplete) {
asyncArray(
fileArray,
function (file, handle) {
fs.readFile(path, 'utf8', function (err, fileContents) {
handle(fileContents);
});
},
function (contentsArray) {
onComplete(contentsArray.join("\n"));
}
);
}

0 comments on commit 2df2dd4

Please sign in to comment.