From 9f41fe9071ea303bb7082a1d756ddb8123774a46 Mon Sep 17 00:00:00 2001 From: Gautam Jethwani Date: Tue, 12 Sep 2023 00:19:19 -0700 Subject: [PATCH] feat: fix nextBucket call in periodic rotations --- lib/status.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/status.js b/lib/status.js index 86128b73..167c311a 100644 --- a/lib/status.js +++ b/lib/status.js @@ -75,10 +75,11 @@ class Status extends EventEmitter { const bucketInterval = Math.floor(this[TIMEOUT] / this[BUCKETS]); if (this.rotateBucketController) { + // rotate the buckets based on an optional EventEmitter this.startListeneningForRotateEvent(); } else { // or rotate the buckets periodically - this[BUCKET_INTERVAL] = setInterval(() => this.rotateBucket(this[WINDOW]), bucketInterval); + this[BUCKET_INTERVAL] = setInterval(nextBucket(this[WINDOW]), bucketInterval); // No unref() in the browser if (typeof this[BUCKET_INTERVAL].unref === 'function') { this[BUCKET_INTERVAL].unref(); @@ -190,10 +191,6 @@ class Status extends EventEmitter { } } - rotateBucket (window) { - nextBucket(window); - } - removeRotateBucketControllerListener () { if (this.rotateBucketController) { this.rotateBucketController.removeListener(this[ROTATE_EVENT_NAME], nextBucket(this[WINDOW])); @@ -202,7 +199,6 @@ class Status extends EventEmitter { startListeneningForRotateEvent () { if (this.rotateBucketController) { - // this.rotateBucketController.on(this[ROTATE_EVENT_NAME], () => this.rotateBucket(this[WINDOW])); this.rotateBucketController.on(this[ROTATE_EVENT_NAME], nextBucket(this[WINDOW])); } }