In #50 I made an early start with this, but I made two mistakes:
Putting the signal in per-method options, e.g. iterator.next({ signal }), rather than in constructor options, i.e. db.iterator({ signal }). The former would not be accessible in a for await...of and come with a performance penalty.
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 and explained 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')
}
}
Further explained in the README, for the public API and the private API (second paragraph).
This PR also fixes small bugs in the open() and close() methods of multiple classes, as follow-up for #50.
In #50 I made an early start with this, but I made two mistakes:
iterator.next({ signal })
, rather than in constructor options, i.e.db.iterator({ signal })
. The former would not be accessible in afor await...of
and come with a performance penalty.abortOnClose
(#21) which is a separate issue. I'll leave it at that, because it only matters formany-level
and can be solved and explained later.Anyway, this PR enables the following:
Further explained in the README, for the public API and the private API (second paragraph).
This PR also fixes small bugs in the
open()
andclose()
methods of multiple classes, as follow-up for #50.