Skip to content

Commit d99a71b

Browse files
perf(cluster): use timer.refresh()
Reference: https://nodejs.org/api/timers.html#timeoutrefresh
1 parent 39d4220 commit d99a71b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/cluster-adapter.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -719,13 +719,14 @@ export abstract class ClusterAdapterWithHeartbeat extends ClusterAdapter {
719719

720720
private scheduleHeartbeat() {
721721
if (this.heartbeatTimer) {
722-
clearTimeout(this.heartbeatTimer);
722+
this.heartbeatTimer.refresh();
723+
} else {
724+
this.heartbeatTimer = setTimeout(() => {
725+
this.publish({
726+
type: MessageType.HEARTBEAT,
727+
});
728+
}, this._opts.heartbeatInterval);
723729
}
724-
this.heartbeatTimer = setTimeout(() => {
725-
this.publish({
726-
type: MessageType.HEARTBEAT,
727-
});
728-
}, this._opts.heartbeatInterval);
729730
}
730731

731732
override close() {

0 commit comments

Comments
 (0)