Closed vweevers closed 3 years ago
Ah. Implementations like memdown
that don't need an explicit end()
call can implement asyncIterator
themselves without an async generator, thus avoiding syntax errors in older runtimes. The level-js
iterator currently does need an explicit end()
but that will change with https://github.com/Level/level-js/issues/86.
So we don't have to do it in userland. The strategy is:
abstract-leveldown
implements Symbol.asyncIterator
with an async generator, lazily required (only in node 10+) and excluded from browserify/webpack buildsmemdown
(and later level-js
) implements Symbol.asyncIterator
without async generatorSuperseded by #379.
Do not merge. Ignore failing tests.
This is to find out what we need to support
Symbol.asyncIterator
in userland (we cannot do it here because we need async generators to properly handle ending on errors, and async generators are only available in Node 10+ and Chrome).The answer is that we need to add Promise support to
iterator.next()
and.end()
. We can do that in the same way aslevelup
: if you don't provide a callback argument, you get back a Promise.This means there will be three ways to iterate:
async/await
(a bit awkward)for await...of
cc @chjj @peakji
Previous discussions: