Skip to content

Commit 7b130e9

Browse files
committed
Fix local datastore heartbeat
1 parent e9e42eb commit 7b130e9

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

es5.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,11 @@
17861786

17871787
var base;
17881788

1789-
if (this.heartbeat == null && (this.storeOptions.reservoirRefreshInterval != null && this.storeOptions.reservoirRefreshAmount != null || this.storeOptions.reservoirIncreaseInterval != null && this.storeOptions.reservoirIncreaseAmount != null)) {
1789+
if (this.heartbeat != null) {
1790+
clearInterval(this.heartbeat);
1791+
}
1792+
1793+
if (this.storeOptions.reservoirRefreshInterval != null && this.storeOptions.reservoirRefreshAmount != null || this.storeOptions.reservoirIncreaseInterval != null && this.storeOptions.reservoirIncreaseAmount != null) {
17901794
return typeof (base = this.heartbeat = setInterval(function () {
17911795
var amount, incr, maximum, now, reservoir;
17921796
now = Date.now();
@@ -1812,8 +1816,6 @@
18121816
}
18131817
}
18141818
}, this.heartbeatInterval)).unref === "function" ? base.unref() : void 0;
1815-
} else {
1816-
return clearInterval(this.heartbeat);
18171819
}
18181820
}
18191821
}, {

lib/LocalDatastore.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ LocalDatastore = class LocalDatastore {
2626
_startHeartbeat() {
2727
var base;
2828

29-
if (this.heartbeat == null && (this.storeOptions.reservoirRefreshInterval != null && this.storeOptions.reservoirRefreshAmount != null || this.storeOptions.reservoirIncreaseInterval != null && this.storeOptions.reservoirIncreaseAmount != null)) {
29+
if (this.heartbeat != null) {
30+
clearInterval(this.heartbeat);
31+
}
32+
33+
if (this.storeOptions.reservoirRefreshInterval != null && this.storeOptions.reservoirRefreshAmount != null || this.storeOptions.reservoirIncreaseInterval != null && this.storeOptions.reservoirIncreaseAmount != null) {
3034
return typeof (base = this.heartbeat = setInterval(() => {
3135
var amount, incr, maximum, now, reservoir;
3236
now = Date.now();
@@ -52,8 +56,6 @@ LocalDatastore = class LocalDatastore {
5256
}
5357
}
5458
}, this.heartbeatInterval)).unref === "function" ? base.unref() : void 0;
55-
} else {
56-
return clearInterval(this.heartbeat);
5759
}
5860
}
5961

light.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,10 @@
477477

478478
_startHeartbeat() {
479479
var base;
480-
if ((this.heartbeat == null) && (((this.storeOptions.reservoirRefreshInterval != null) && (this.storeOptions.reservoirRefreshAmount != null)) || ((this.storeOptions.reservoirIncreaseInterval != null) && (this.storeOptions.reservoirIncreaseAmount != null)))) {
480+
if (this.heartbeat != null) {
481+
clearInterval(this.heartbeat);
482+
}
483+
if (((this.storeOptions.reservoirRefreshInterval != null) && (this.storeOptions.reservoirRefreshAmount != null)) || ((this.storeOptions.reservoirIncreaseInterval != null) && (this.storeOptions.reservoirIncreaseAmount != null))) {
481484
return typeof (base = (this.heartbeat = setInterval(() => {
482485
var amount, incr, maximum, now, reservoir;
483486
now = Date.now();
@@ -500,8 +503,6 @@
500503
}
501504
}
502505
}, this.heartbeatInterval))).unref === "function" ? base.unref() : void 0;
503-
} else {
504-
return clearInterval(this.heartbeat);
505506
}
506507
}
507508

src/LocalDatastore.coffee

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class LocalDatastore
1414
@_startHeartbeat()
1515

1616
_startHeartbeat: ->
17-
if !@heartbeat? and ((
17+
if @heartbeat? then clearInterval @heartbeat
18+
19+
if ((
1820
@storeOptions.reservoirRefreshInterval? and @storeOptions.reservoirRefreshAmount?
1921
) or (
2022
@storeOptions.reservoirIncreaseInterval? and @storeOptions.reservoirIncreaseAmount?
@@ -36,7 +38,6 @@ class LocalDatastore
3638
@instance._drainAll @computeCapacity()
3739

3840
, @heartbeatInterval).unref?()
39-
else clearInterval @heartbeat
4041

4142
__publish__: (message) ->
4243
await @yieldLoop()

0 commit comments

Comments
 (0)