Skip to content

Commit

Permalink
add transit.serviceChangedDebounceTime broker option to control the d…
Browse files Browse the repository at this point in the history
…ebounce time of serviceChanged handler
  • Loading branch information
icebob committed Nov 14, 2024
1 parent 7683348 commit 3681559
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/service-broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ const defaultOptions = {
maxQueueSize: 50 * 1000, // 50k ~ 400MB,
maxChunkSize: 256 * 1024, // 256KB
disableReconnect: false,
disableVersionCheck: false
disableVersionCheck: false,
serviceChangedDebounceTime: 1000
},

uidGenerator: null,
Expand Down Expand Up @@ -305,9 +306,14 @@ class ServiceBroker {
this.call = this.callWithoutBalancer;
}

// Create debounced localServiceChanged
const origLocalServiceChanged = this.localServiceChanged;
this.localServiceChanged = _.debounce(() => origLocalServiceChanged.call(this), 1000);
if (this.options.transit.serviceChangedDebounceTime > 0) {
// Create debounced localServiceChanged
const origLocalServiceChanged = this.localServiceChanged;
this.localServiceChanged = _.debounce(
() => origLocalServiceChanged.call(this),
this.options.transit.serviceChangedDebounceTime
);
}

this.registry.init(this);

Expand Down
3 changes: 2 additions & 1 deletion test/unit/service-broker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ describe("Test ServiceBroker constructor", () => {
disableReconnect: false,
maxQueueSize: 50 * 1000,
maxChunkSize: 262144,
disableVersionCheck: false
disableVersionCheck: false,
serviceChangedDebounceTime: 1000
},

uidGenerator: null,
Expand Down

0 comments on commit 3681559

Please sign in to comment.