rocksdb-native 3.7.2 → 3.7.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.
package/lib/state.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const ReadyResource = require('ready-resource')
2
2
  const RefCounter = require('refcounter')
3
3
  const rrp = require('resolve-reject-promise')
4
+ const SignalPromise = require('signal-promise')
4
5
  const { ReadBatch, WriteBatch } = require('./batch')
5
6
  const ColumnFamily = require('./column-family')
6
7
  const binding = require('../binding')
@@ -33,8 +34,9 @@ module.exports = class RocksDBState extends ReadyResource {
33
34
  this.resumed = null
34
35
 
35
36
  this._suspended = false
36
- this._suspending = null
37
- this._resuming = null
37
+ this._suspending = false
38
+ this._updating = false
39
+ this._updatingSignal = new SignalPromise()
38
40
  this._columnsFlushed = false
39
41
  this._readBatches = []
40
42
  this._writeBatches = []
@@ -158,6 +160,7 @@ module.exports = class RocksDBState extends ReadyResource {
158
160
  }
159
161
 
160
162
  async _close() {
163
+ while (this._updating) await this._updatingSignal.wait()
161
164
  if (this.resumed) this.resumed.resolve(false)
162
165
 
163
166
  while (!this.io.isIdle()) await this.io.idle()
@@ -227,20 +230,30 @@ module.exports = class RocksDBState extends ReadyResource {
227
230
  }
228
231
  }
229
232
 
230
- async suspend() {
231
- if (this._suspending === null) this._suspending = this._suspend()
232
- return this._suspending
233
+ suspend() {
234
+ this._suspending = true
235
+ return this.update()
233
236
  }
234
237
 
235
- async _suspend() {
236
- if (this.opened === false) await this.ready()
237
-
238
- this.io.inc()
239
-
240
- if (this._resuming !== null) await this._resuming
238
+ resume() {
239
+ this._suspending = false
240
+ return this.update()
241
+ }
241
242
 
242
- this.io.dec()
243
+ async update() {
244
+ while (this._updating) await this._updatingSignal.wait()
245
+ if (this._suspending === this._suspended || this.closing) return
246
+ this._updating = true
247
+ try {
248
+ if (this._suspending) await this._suspend()
249
+ else await this._resume()
250
+ } finally {
251
+ this._updating = false
252
+ this._updatingSignal.notify()
253
+ }
254
+ }
243
255
 
256
+ async _suspend() {
244
257
  if (this._suspended === true) return
245
258
 
246
259
  while (!this.io.isIdle()) await this.io.idle()
@@ -263,8 +276,6 @@ module.exports = class RocksDBState extends ReadyResource {
263
276
  this._suspended = true
264
277
  } finally {
265
278
  this.io.dec()
266
-
267
- this._suspending = null
268
279
  }
269
280
 
270
281
  function onsuspend(err) {
@@ -273,19 +284,8 @@ module.exports = class RocksDBState extends ReadyResource {
273
284
  }
274
285
  }
275
286
 
276
- resume() {
277
- if (this._resuming === null) this._resuming = this._resume()
278
- return this._resuming
279
- }
280
-
281
287
  async _resume() {
282
- if (this.opened === false) await this.ready()
283
-
284
- this.io.inc()
285
-
286
- if (this._suspending !== null) await this._suspending
287
-
288
- if (this._suspended === false) return this.io.dec()
288
+ if (this._suspended === false) return
289
289
 
290
290
  const req = { resolve: null, reject: null, handle: null }
291
291
 
@@ -294,17 +294,11 @@ module.exports = class RocksDBState extends ReadyResource {
294
294
  req.reject = reject
295
295
  })
296
296
 
297
- try {
298
- req.handle = binding.resume(this._handle, req, onresume)
299
-
300
- await promise
297
+ req.handle = binding.resume(this._handle, req, onresume)
301
298
 
302
- this._suspended = false
303
- } finally {
304
- this.io.dec()
299
+ await promise
305
300
 
306
- this._resuming = null
307
- }
301
+ this._suspended = false
308
302
 
309
303
  const resumed = this.resumed
310
304
  this.resumed = null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rocksdb-native",
3
- "version": "3.7.2",
3
+ "version": "3.7.4",
4
4
  "description": "librocksdb bindings for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -41,6 +41,7 @@
41
41
  "refcounter": "^1.0.0",
42
42
  "require-addon": "^1.0.2",
43
43
  "resolve-reject-promise": "^1.1.0",
44
+ "signal-promise": "^1.0.3",
44
45
  "streamx": "^2.16.1"
45
46
  },
46
47
  "devDependencies": {