hypercore-storage 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/index.js +15 -5
  2. 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.flushing = false
31
32
  this.flushes = []
32
33
  }
33
34
 
@@ -36,13 +37,21 @@ class Atom {
36
37
  }
37
38
 
38
39
  async flush () {
39
- await View.flush(this.view.changes, this.db)
40
- this.view.reset()
40
+ if (this.flushing) throw new Error('Atom already flushing')
41
+ this.flushing = true
41
42
 
42
- const promises = []
43
- for (let i = 0; i < this.flushes.length; i++) promises.push(this.flushes[i]())
43
+ try {
44
+ await View.flush(this.view.changes, this.db)
45
+ this.view.reset()
46
+
47
+ const promises = []
48
+ const len = this.flushing.length // in case of reentry
49
+ for (let i = 0; i < len; i++) promises.push(this.flushes[i]())
44
50
 
45
- await Promise.all(promises)
51
+ await Promise.all(promises)
52
+ } finally {
53
+ this.flushing = false
54
+ }
46
55
  }
47
56
  }
48
57
 
@@ -99,6 +108,7 @@ class HypercoreStorage {
99
108
  }
100
109
 
101
110
  atomize (atom) {
111
+ if (this.atom && this.atom !== atom) throw new Error('Cannot atomize and atomized session with a new atom')
102
112
  return new HypercoreStorage(this.store, this.db.session(), this.core, atom.view, atom)
103
113
  }
104
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",