Skip to content

Commit c41d3c0

Browse files
committed
fix: Delay applying when reclaimDelay is disabled because of clock synchronization
1 parent 0325c2a commit c41d3c0

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { Persistency } from "persistency";
2828

2929
const persistency = new Persistency({
3030
folder: "/path/to/data/folder",
31-
reclaimTimeout: 10000 // Milliseconds. Optional. 10 seconds by default. Set to 0 or negative to directly delete old entries without any waiting
31+
reclaimDelay: 10000 // Milliseconds. Optional. 10 seconds by default. Set to 0 or negative to directly delete old entries without any waiting
3232
});
3333

3434
// The library works with buffers, so you can use any serialization library, like pacopack

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "persistency",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "The lightweight resilient persistency library",
55
"main": "lib/",
66
"types": "lib/types",

src/Persistency.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ export class Persistency {
7171
};
7272
this.entriesFile = Path.join(options.folder, "entries.db");
7373
this.dataFile = Path.join(options.folder, "data.db");
74-
this.reclaimTimeout = options.reclaimTimeout != null ? options.reclaimTimeout : 10000;
74+
if (options.reclaimDelay == null) {
75+
this.reclaimDelay = 10000;
76+
} else if (options.reclaimDelay > 0) {
77+
this.reclaimDelay = options.reclaimDelay;
78+
} else {
79+
this.reclaimDelay = 0;
80+
this._context.now = () => 0; // Avoids overhead and applying delays because of clock synchronizing forwards/backwards
81+
}
7582
this._fd = this._loadDataSync();
7683
this._checkReclaim();
7784
this._compact();

0 commit comments

Comments
 (0)