hypercore-storage 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +14 -0
- package/lib/view.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -28,6 +28,7 @@ class Atom {
|
|
|
28
28
|
constructor (db) {
|
|
29
29
|
this.db = db
|
|
30
30
|
this.view = new View()
|
|
31
|
+
this.flushedPromise = null
|
|
31
32
|
this.flushing = false
|
|
32
33
|
this.flushes = []
|
|
33
34
|
}
|
|
@@ -36,6 +37,18 @@ class Atom {
|
|
|
36
37
|
this.flushes.push(fn)
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
flushed () {
|
|
41
|
+
if (!this.flushing) return Promise.resolve()
|
|
42
|
+
this.flushedPromise = rrp()
|
|
43
|
+
return this.flushedPromise.promise
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_resolve () {
|
|
47
|
+
const f = this.flushedPromise
|
|
48
|
+
this.flushedPromise = null
|
|
49
|
+
f.resolve()
|
|
50
|
+
}
|
|
51
|
+
|
|
39
52
|
async flush () {
|
|
40
53
|
if (this.flushing) throw new Error('Atom already flushing')
|
|
41
54
|
this.flushing = true
|
|
@@ -51,6 +64,7 @@ class Atom {
|
|
|
51
64
|
await Promise.all(promises)
|
|
52
65
|
} finally {
|
|
53
66
|
this.flushing = false
|
|
67
|
+
if (this.flushedPromise !== null) this._resolve()
|
|
54
68
|
}
|
|
55
69
|
}
|
|
56
70
|
}
|
package/lib/view.js
CHANGED