Skip to content

Commit d1c314c

Browse files
committed
fix: add a margin of safety to renew mutex early
1 parent ac65928 commit d1c314c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Mutex.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ module.exports = class Mutex {
99
this._store = new idb.Store(this._database + "_lock", this._database + "_lock")
1010
this._lock = null
1111
}
12-
async has () {
12+
async has ({ margin = 2000 } = {}) {
1313
if (this._lock && this._lock.holder === this._id) {
1414
const now = Date.now()
15-
if (this._lock.expires > now) {
15+
if (this._lock.expires > now + margin) {
1616
return true
1717
} else {
1818
return await this.renew()

0 commit comments

Comments
 (0)