diff --git a/src/lib/data_structures/publication_tree.ts b/src/lib/data_structures/publication_tree.ts index 0b16045..4306b1e 100644 --- a/src/lib/data_structures/publication_tree.ts +++ b/src/lib/data_structures/publication_tree.ts @@ -223,7 +223,7 @@ export class PublicationTree implements AsyncIterable { } async next(): Promise> { - while (this.#cursor.target?.type !== PublicationTreeNodeType.Leaf) { + do { if (await this.#cursor.tryMoveToFirstChild()) { continue; } @@ -232,14 +232,14 @@ export class PublicationTree implements AsyncIterable { continue; } - if (await this.#cursor.tryMoveToParent()) { + if (this.#cursor.tryMoveToParent()) { continue; } if (this.#cursor.target?.type === PublicationTreeNodeType.Root) { return { done: true, value: null }; } - } + } while (this.#cursor.target?.type !== PublicationTreeNodeType.Leaf); const event = await this.getEvent(this.#cursor.target!.address); return { done: false, value: event! };