fix: End iterator if returning early from forEachMessage (#800)

This commit is contained in:
adityapk00
2023-04-04 09:06:12 -05:00
committed by GitHub
parent da9cf2939a
commit 54dbf42fb5
2 changed files with 9 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'@farcaster/hubble': patch
---
End iterator in while rebulding trie

View File

@@ -342,9 +342,11 @@ class Engine {
async forEachMessage(callback: (message: protobufs.Message, key: Buffer) => Promise<boolean | void>): Promise<void> {
const allUserPrefix = Buffer.from([RootPrefix.User]);
const iterator = this._db.iteratorByPrefix(allUserPrefix, { keys: true });
for await (const [key, value] of this._db.iteratorByPrefix(allUserPrefix, { keys: true })) {
for await (const [key, value] of iterator) {
if (!key || !value) {
await iterator.end();
break;
}
@@ -375,6 +377,7 @@ class Engine {
if (message.isOk()) {
const done = await callback(message.value, key);
if (done) {
await iterator.end();
break;
}
}