Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hidden abortOnClose option to iterators #21

Merged
merged 2 commits into from Mar 20, 2022
Merged

Conversation

vweevers
Copy link
Member

No description provided.

Otherwise they're lost when an implementation clones options.
Will be used by `many-level`.
@vweevers vweevers added the semver-patch Bug fixes that are backward compatible label Mar 13, 2022
@vweevers vweevers merged commit 2935180 into main Mar 20, 2022
@vweevers vweevers deleted the abort-on-close branch March 20, 2022 08:28
vweevers added a commit that referenced this pull request Nov 14, 2022
In #50 I made an early start with this, but I made two mistakes:

1. Putting the signal in per-method options, e.g. `next({ signal })`,
   rather than in constructor options, i.e. `iterator({ signal })`.
   The former would not be accessible in a `for await...of` and
   come with a performance penalty.
2. Thinking it could replace `abortOnClose` (#21), which is a
   separate issue. I'll leave it at that, because it only matters
   for `many-level` and can be solved later.

Anyway, this PR enables the following:

```
const abortController = new AbortController()
const signal = abortController.signal

// Will result in 'aborted' log
abortController.abort()

try {
  for await (const entry of db.iterator({ signal })) {
    console.log(entry)
  }
} catch (err) {
  if (err.code === 'LEVEL_ABORTED') {
    console.log('aborted')
  }
}
```

It also fixes small bugs in the `open()` and `close()` methods of
multiple classes, as follow-up for #50.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch Bug fixes that are backward compatible
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant