Skip to content

Commit

Permalink
server: fix await files and cache synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jul 19, 2016
1 parent 6ccf629 commit a448f2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 5 additions & 7 deletions lib/server/modules/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -103,7 +104,7 @@ function dropFileInfo(filename){

delete fileMap[filename];

resourceCache.remove(filename);
resourceCache.remove(processPath(filename));
}
}

Expand All @@ -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);
},
Expand All @@ -139,7 +138,6 @@ module.exports = {
resourceCache.add(processPath(filename), data);
getFileInfo(filename, true).notify = true;
},

updateCache: function(filename, data){
var relPath = processPath(filename);

Expand Down
6 changes: 4 additions & 2 deletions lib/server/modules/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a448f2f

Please sign in to comment.