From d782d9652ea7ae122e20c774831302334c46fc3f Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 20 Feb 2024 16:39:18 +0100 Subject: [PATCH] perf(cluster): use timer.refresh() Reference: https://nodejs.org/api/timers.html#timeoutrefresh --- lib/cluster-adapter.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/cluster-adapter.ts b/lib/cluster-adapter.ts index 8061f2a..7482d03 100644 --- a/lib/cluster-adapter.ts +++ b/lib/cluster-adapter.ts @@ -719,13 +719,14 @@ export abstract class ClusterAdapterWithHeartbeat extends ClusterAdapter { private scheduleHeartbeat() { if (this.heartbeatTimer) { - clearTimeout(this.heartbeatTimer); + this.heartbeatTimer.refresh(); + } else { + this.heartbeatTimer = setTimeout(() => { + this.publish({ + type: MessageType.HEARTBEAT, + }); + }, this._opts.heartbeatInterval); } - this.heartbeatTimer = setTimeout(() => { - this.publish({ - type: MessageType.HEARTBEAT, - }); - }, this._opts.heartbeatInterval); } override close() {