Skip to content

Commit a79ab5f

Browse files
authored
fix: remove extra while true loop (#79)
1 parent 9192fe5 commit a79ab5f

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/cache/index.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,24 @@ export class LightBlockCache {
6666

6767
private async cacheBlocksInner(): Promise<void> {
6868
const rpc = await ifClient.getClient();
69-
// eslint-disable-next-line no-constant-condition
70-
while (true) {
71-
const head = await this.getHead();
72-
const followChainStreamParams = head
73-
? { head: head.toString("hex") }
74-
: {};
75-
const stream = await rpc.chain.followChainStream({
76-
...followChainStreamParams,
77-
serialized: true,
78-
limit: 100,
79-
});
80-
81-
for await (const content of stream.contentStream()) {
82-
if (content.type === "connected") {
83-
const block = lightBlock(content);
84-
this.cacheBlock(block);
85-
} else if (content.type === "disconnected") {
86-
logger.warn(`Removing block ${content.block.sequence}...`);
87-
const block = lightBlock(content);
88-
await this.putHead(block.previousBlockHash, block.sequence - 1);
89-
await this.del(block.sequence.toString());
90-
await this.del(block.hash.toString("hex"));
91-
}
69+
const head = await this.getHead();
70+
const followChainStreamParams = head ? { head: head.toString("hex") } : {};
71+
const stream = await rpc.chain.followChainStream({
72+
...followChainStreamParams,
73+
serialized: true,
74+
limit: 100,
75+
});
76+
77+
for await (const content of stream.contentStream()) {
78+
if (content.type === "connected") {
79+
const block = lightBlock(content);
80+
this.cacheBlock(block);
81+
} else if (content.type === "disconnected") {
82+
logger.warn(`Removing block ${content.block.sequence}...`);
83+
const block = lightBlock(content);
84+
await this.putHead(block.previousBlockHash, block.sequence - 1);
85+
await this.del(block.sequence.toString());
86+
await this.del(block.hash.toString("hex"));
9287
}
9388
}
9489
}

0 commit comments

Comments
 (0)