You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-1Lines changed: 33 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -219,7 +219,39 @@ db.open(function (err) {
219
219
})
220
220
```
221
221
222
-
_TBD: whether this also includes methods like `isOpen()` and `isClosed()`._
222
+
### `idempotentOpen` (boolean)
223
+
224
+
Are `db.open()` and `db.close()` idempotent and safe, such that:
225
+
226
+
1. Calling `open()` or `close()` twice has the same effect as calling it once
227
+
2. If both `open()` and `close()` are called in succession while a previous call has not yet completed, the last call dictates the final `status` and all earlier calls yield an error if they oppose the final `status`.
228
+
3. Callbacks are called in the order that the `open()` or `close()` calls were made.
229
+
4. Callbacks are not called until any pending state changes are done, meaning that `status` is not (or no longer) 'opening' or 'closing'.
230
+
5. If events are supported, they are emitted before callbacks are called, because event listeners may result in additional pending state changes.
231
+
6. If events are supported, the 'open' and 'closed' events are not emitted if there are pending state changes or if the initial `status` matches the final `status`. They communicate a changed final `status` even though the (underlying) db may open and close multiple times before that. This avoids emitting (for example) an 'open' event while `status` is 'closing'.
232
+
233
+
For example:
234
+
235
+
1. In a sequence of calls like `open(); close(); open()` the final `status` will be 'open', the second call will receive an error, an 'open' event is emitted once, no 'closed' event is emitted, and all callbacks will see that `status` is 'open'. That is unless `open()` failed.
236
+
2. If `open()` failed twice in the same sequence of calls, the final status will be 'closed', the first and last call receive an error, no events are emitted, and all callbacks will see that `status` is 'closed'.
237
+
238
+
_At the time of writing this is a new feature, subject to change, zero modules support it (including `levelup`)._
239
+
240
+
### `passiveOpen` (boolean)
241
+
242
+
Does db support `db.open({ passive: true })` which waits for but does not initiate opening? To the same but more comprehensive effect as :
243
+
244
+
```js
245
+
if (db.status==='opening') {
246
+
db.once('open', callback)
247
+
} elseif (db.status==='open') {
248
+
queueMicrotask(callback)
249
+
} else {
250
+
// Yield error
251
+
}
252
+
```
253
+
254
+
_At the time of writing this is a new feature, subject to change, zero modules support it._
0 commit comments