From 38324204a5bc93c67339807575f908761da6fc51 Mon Sep 17 00:00:00 2001 From: Ahmad Ganjtabesh Date: Fri, 14 Apr 2023 12:26:07 +0330 Subject: [PATCH] perf: postpone restarting to the last change --- lib/Watcher.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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;