diff --git a/lib/server/modules/files.js b/lib/server/modules/files.js index 8f1f650..3ae844b 100644 --- a/lib/server/modules/files.js +++ b/lib/server/modules/files.js @@ -20,16 +20,17 @@ function checkQueue(){ readFile(filesToRead.shift()); } +// processingPaths[key] -> [callbackN .. callback1 onRead1 ... onReadN] function addFileToQueue(filename, callback){ if (processingPaths[filename]) { if (typeof callback == 'function') - processingPaths[filename].push(callback); + processingPaths[filename].unshift(callback); return; } processingPaths[filename] = typeof callback == 'function' - ? readCallbacks.concat(callback) + ? [callback].concat(readCallbacks) : readCallbacks.slice(); if (readingCount < READ_LIMIT) @@ -103,7 +104,7 @@ function dropFileInfo(filename){ delete fileMap[filename]; - resourceCache.remove(filename); + resourceCache.remove(processPath(filename)); } } @@ -127,10 +128,8 @@ module.exports = { removeCallbacks.push(callback); }, onRead: function(callback){ - var pos = readCallbacks.length; - for (var filename in processingPaths) - processingPaths[filename].splice(pos, 0, filename); + processingPaths[filename].push(callback); readCallbacks.push(callback); }, @@ -139,7 +138,6 @@ module.exports = { resourceCache.add(processPath(filename), data); getFileInfo(filename, true).notify = true; }, - updateCache: function(filename, data){ var relPath = processPath(filename); diff --git a/lib/server/modules/watch.js b/lib/server/modules/watch.js index 1078b85..768ced2 100644 --- a/lib/server/modules/watch.js +++ b/lib/server/modules/watch.js @@ -64,8 +64,10 @@ function getWatcher(dirInfo){ else if (dirInfo.awaitFiles.has(filename)) { dirInfo.awaitFiles.delete(filename); - files.addToCache(filename); - files.readFile(filename); + files.readFile(filename, function(err, content){ + if (!err) + files.addToCache(filename, content); + }); } } else