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
+13-5Lines changed: 13 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -568,7 +568,7 @@ db.foo = async function (key) {
568
568
569
569
The optional `options` object may contain:
570
570
571
-
-`signal`: an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to abort the deferred operation. When aborted (now or later) the `fn` function will not be called, and the promise returned by `deferAsync()` will be rejected with a [`LEVEL_ABORTED`](#errors) error.
571
+
-`signal`: an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to abort the deferred operation. When aborted (now or later) the `fn` function will not be called, and the promise returned by `deferAsync()` will be rejected with a [`LEVEL_ABORTED`](#level_aborted) error.
Iterators take an experimental `signal` option that, once signaled, aborts an in-progress read operation (if any) and rejects subsequent reads. The relevant promise will be rejected with a [`LEVEL_ABORTED`](#errors) error. Aborting does not close the iterator, because closing is asynchronous and may result in an error that needs a place to go. This means signals should be used together with a pattern that automatically closes the iterator:
737
+
Iterators take an experimental `signal` option that, once signaled, aborts an in-progress read operation (if any) and rejects subsequent reads. The relevant promise will be rejected with a [`LEVEL_ABORTED`](#level_aborted) error. Aborting does not close the iterator, because closing is asynchronous and may result in an error that needs a place to go. This means signals should be used together with a pattern that automatically closes the iterator:
738
738
739
739
```js
740
740
constabortController=newAbortController()
@@ -770,6 +770,8 @@ try {
770
770
}
771
771
```
772
772
773
+
Support of signals is indicated via [`db.supports.signals.iterators`](https://github.com/Level/supports#signals-object).
774
+
773
775
### `keyIterator`
774
776
775
777
A key iterator has the same interface as `iterator` except that its methods yield keys instead of entries. Usage is otherwise the same.
@@ -1212,7 +1214,13 @@ When an operation was made on a chained batch while it was closing or closed, wh
1212
1214
1213
1215
#### `LEVEL_ABORTED`
1214
1216
1215
-
When an operation was aborted by the user.
1217
+
When an operation was aborted by the user. For [web compatibility](https://dom.spec.whatwg.org/#aborting-ongoing-activities) this error can also be identified by its `name` which is `'AbortError'`:
1218
+
1219
+
```js
1220
+
if (err.name==='AbortError') {
1221
+
// Operation was aborted
1222
+
}
1223
+
```
1216
1224
1217
1225
#### `LEVEL_ENCODING_NOT_FOUND`
1218
1226
@@ -1617,13 +1625,13 @@ class ExampleSublevel extends AbstractSublevel {
1617
1625
1618
1626
The first argument to this constructor must be an instance of the relevant `AbstractLevel` implementation. The constructor will set `iterator.db` which is used (among other things) to access encodings and ensures that `db` will not be garbage collected in case there are no other references to it. The `options` argument must be the original `options` object that was passed to `db._iterator()` and it is therefore not (publicly) possible to create an iterator via constructors alone.
1619
1627
1620
-
The `signal` option, if any and once signaled, should abort an in-progress `_next()`, `_nextv()` or `_all()` call and reject the promise returned by that call with a [`LEVEL_ABORTED`](#errors) error. Doing so is optional until a future semver-major release. Responsibilities are divided as follows:
1628
+
The `signal` option, if any and once signaled, should abort an in-progress `_next()`, `_nextv()` or `_all()` call and reject the promise returned by that call with a [`LEVEL_ABORTED`](#level_aborted) error. Doing so is optional until a future semver-major release. Responsibilities are divided as follows:
1621
1629
1622
1630
1. Before a database has finished opening, `abstract-level` handles the signal
1623
1631
2. While a call is in progress, the implementation handles the signal
1624
1632
3. Once the signal is aborted, `abstract-level` rejects further calls.
1625
1633
1626
-
A method like `_next()` therefore doesn't have to check the signal _before_ it start its asynchronous work, only _during_ that work. Whether to respect the signal and on which (potentially long-running) methods, is up to the implementation.
1634
+
A method like `_next()` therefore doesn't have to check the signal _before_ it start its asynchronous work, only _during_ that work. If supported, set `db.supports.signals.iterators`to `true` (via the manifest passed to the database constructor) which also enables relevant tests in the [test suite](#test-suite).
0 commit comments