Permalink
Browse files

Added simple queue to local test client

  • Loading branch information...
davidmerfield committed Nov 30, 2018
1 parent 396c9cb commit 138f4ab373ff54365db1be9b0b6f8f14b9b513f5
Showing with 21 additions and 4 deletions.
  1. +21 −4 app/clients/local/controllers/sync.js
@@ -36,10 +36,26 @@ function walk(dir) {
}
function init(blogID, userFolder, callback) {
var watcher = fs.watch(userFolder, { recursive: true }, handler);
var queue = async.queue(function(task, callback) {
console.log("Beginning sync...");
handler(task.event, task.path, function(err) {
if (err) console.log(err);
console.log("Finished sync...");
callback();
});
});
var watcher = fs.watch(userFolder, { recursive: true }, function(
event,
path
) {
queue.push({ event: event, path: path });
});
callback(null);
function handler(event, path) {
function handler(event, path, callback) {
if (!path) return;
// Blot likes leading slashes
@@ -55,7 +71,7 @@ function init(blogID, userFolder, callback) {
if (!folder) return watcher.close();
Sync(blogID, syncOptions, function(err, folder, done) {
if (err) return console.log(err);
if (err) return callback(err);
fs.stat(pathInUserFolder, function(err, stat) {
try {
@@ -83,7 +99,8 @@ function init(blogID, userFolder, callback) {
async.each(affectedPaths, folder.update, function(err) {
if (err) console.log(err);
done(null, function(err) {
if (err) console.log(err);
if (err) return callback(err);
callback();
});
});
});

0 comments on commit 138f4ab

Please sign in to comment.