diff --git a/lib/assetmanager.js b/lib/assetmanager.js index 769430e..79565c5 100644 --- a/lib/assetmanager.js +++ b/lib/assetmanager.js @@ -5,7 +5,8 @@ var fs = require('fs') , jsmin = require('./../deps/jsmin').minify , htmlmin = require('./../deps/htmlmin').minify , cssmin = require('./../deps/cssmin').minify - , crypto = require('crypto'); + , crypto = require('crypto') + , async = require('async'); var zlib; try { @@ -17,6 +18,25 @@ var cache = {} , cacheHashes = {} , cacheTimestamps = {}; +var q = async.queue(function (task, callback) { + (function (task, fileInfo) { + file = task.file + fileInfo = task.fileInfo + fs.readFile(file, function (err, data) { + if (err) { + console.log('Could not find: '+file); + callback(null, ''); + return; + } + fileInfo.content = data.toString(); + fs.stat(file, function (err, stat) { + fileInfo.modified = stat.mtime; + callback(null, fileInfo); + }); + }); + })(task); +}, 10); + module.exports = function assetManager (assets) { var self = this; @@ -142,6 +162,7 @@ module.exports = function assetManager (assets) { userAgentMatches = Object.keys(userAgentMatches); } + userAgentMatches.forEach(function(match) { var path = group.path; Step(function () { @@ -306,21 +327,9 @@ module.exports = function assetManager (assets) { callback(null, fileInfo); }); } else { - setTimeout(function() { - fs.readFile(path+file, function (err, data) { - if (err) { - console.log('Could not find: '+file); - callback(null, ''); - return; - } - fileInfo.content = data.toString(); - - fs.stat(path+file, function (err, stat) { - fileInfo.modified = stat.mtime; - callback(null, fileInfo); - }); - }); - }, 100); + q.push({fileInfo: fileInfo, file: path+file}, function (err, fileInfo) { + callback(err, fileInfo); + }); } }; diff --git a/package.json b/package.json index e5fa145..463ec1e 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,11 @@ "directories" : { "lib" : "./lib" }, "main" : "./lib/assetmanager", "repository" : [ - { "type":"git", "url":"http://github.com/mape/connect-assetmanager.git" } + { "type":"git", "url":"http://github.com/lordkada/connect-assetmanager.git" } ], "dependencies" : { "request" : ">=0.10.0", - "step" : ">=0.0.3" + "step" : ">=0.0.3", + "async" : "0.1.22" } }