Created
April 13, 2014 10:46
-
-
Save zuchmanski/10578720 to your computer and use it in GitHub Desktop.
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
var async = require('async'); | |
var file = require('file'); | |
var fs = require('fs'); | |
var Q = require('q'); | |
function printAsync(s, cb) { | |
var delay = Math.floor((Math.random()*1000)+500); | |
setTimeout(function() { | |
console.log(s); | |
if (cb) cb(); | |
}, delay); | |
} | |
// Q | |
function qPrintAsync(s) { | |
var deferred = Q.defer(); | |
printAsync(s, function() { | |
deferred.resolve(); | |
}); | |
return deferred.promise; | |
} | |
qPrintAsync(1) | |
.then(function () { | |
return qPrintAsync(2); | |
}).then(function () { | |
return qPrintAsync(3); | |
}).then(function () { | |
return qPrintAsync(4); | |
}); | |
// 1 | |
// | |
printAsync("1", function () { | |
printAsync("2", function () { | |
printAsync("3"); | |
}); | |
}); | |
var functions = []; | |
// | |
async.waterfall([ | |
function(cb) { | |
}, | |
function(cb) { | |
printAsync("2", cb); | |
}, | |
function(cb) { | |
printAsync("3", cb); | |
}]); | |
// 3 | |
// | |
//var globalCount = 0; | |
file.walk("/Users/sebcioz/Downloads/PAM08", function (a, dirPath, dirs, files) { | |
files.forEach(function (file) { | |
var count = 0; | |
console.log(file); | |
fs.createReadStream(file).on('data', function(chunk) { | |
count += chunk.toString('utf8') | |
.split(/\r\n|[\n\r\u0085\u2028\u2029]/g) | |
.length-1; | |
}).on('end', function() { | |
console.log(file, count); | |
globalCount += count; | |
}).on('error', function(err) { | |
console.error(err); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment