Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Support for await...of db.iterator() #379

Merged
merged 2 commits into from
Sep 21, 2021
Merged

Conversation

vweevers
Copy link
Member

@vweevers vweevers commented Sep 12, 2021

Closes #235. You can now do:

try {
  for await (const [key, value] of db.iterator()) {
    console.log(key)
  }
} catch (err) {
  console.error(err)
}

Supersedes #338, which was just a proof of concept and we've since dropped support of legacy runtimes (Level/community#98) which now allows us to use async generators across the board.

Closes #235.

Supersedes #338, which was just a proof of concept and we've since
dropped support of legacy runtimes (Level/community#98) which now
allows us to use async generators across the board.
@vweevers vweevers added the semver-minor New features that are backward compatible label Sep 12, 2021
vweevers added a commit to Level/leveldown that referenced this pull request Sep 12, 2021
vweevers added a commit to Level/level-js that referenced this pull request Sep 12, 2021
vweevers added a commit to Level/memdown that referenced this pull request Sep 12, 2021
@vweevers
Copy link
Member Author

Might want to add keys and values options before it's too late to change the function signature. We could do:

for await (const key of db.iterator({ values: false }))

But I think I prefer a new API, in which case it's not a blocker:

for await (const key of db.keyIterator())

Or even:

for await (const key of db.keys())

@ralphtheninja
Copy link
Member

I prefer the last one.

@vweevers vweevers merged commit 372695f into master Sep 21, 2021
@vweevers vweevers deleted the async-iterator-reboot branch September 21, 2021 12:22
@vweevers
Copy link
Member Author

7.1.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
semver-minor New features that are backward compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Symbol.asyncIterator to iterator
2 participants