diff --git a/lib/Watcher.js b/lib/Watcher.js index 9dbe6b095..2e116a255 100644 --- a/lib/Watcher.js +++ b/lib/Watcher.js @@ -51,6 +51,8 @@ module.exports = function ClusterMode(God) { console.log('[Watch] Start watching', pm2_env.name); + var timeoutId; + watcher.on('all', function(event, path) { var self = this; @@ -63,7 +65,10 @@ module.exports = function ClusterMode(God) { console.log('Change detected on path %s for app %s - restarting', path, pm2_env.name); - setTimeout(function() { + if (timeoutId) { + clearTimeout(timeoutId) + } + timeoutId = setTimeout(function() { God.restartProcessName(pm2_env.name, function(err, list) { self.restarting = false;