refactor: split subscribe into syncToLatestBlock

This commit is contained in:
Derrick Hammer 2023-07-13 03:18:05 -04:00
parent 4836ddb32e
commit 11791ff08b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 13 additions and 9 deletions

View File

@ -154,6 +154,11 @@ export default abstract class BaseClient {
protected async subscribe(callback?: (ei: ExecutionInfo) => void) {
setInterval(async () => {
await this.syncToLatestBlock(callback);
}, POLLING_DELAY);
}
public async syncToLatestBlock(callback?: (ei: ExecutionInfo) => void) {
try {
const ei = await this.getLatestExecution();
if (ei && ei.blockHash !== this.latestBlockHash) {
@ -163,7 +168,6 @@ export default abstract class BaseClient {
} catch (e) {
console.error(e);
}
}, POLLING_DELAY);
}
protected async getLatestExecution(): Promise<ExecutionInfo | null> {