Skip to content

Add hidden abortOnClose option to iterators#21

Merged
vweevers merged 2 commits intomainfrom
abort-on-close
Mar 20, 2022
Merged

Add hidden abortOnClose option to iterators#21
vweevers merged 2 commits intomainfrom
abort-on-close

Conversation

@vweevers
Copy link
Copy Markdown
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 vweevers mentioned this pull request Mar 20, 2022
40 tasks
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

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant