diff --git a/src/baseClient.ts b/src/baseClient.ts index a9c0449..3a82f0d 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -154,18 +154,22 @@ export default abstract class BaseClient { protected async subscribe(callback?: (ei: ExecutionInfo) => void) { setInterval(async () => { - try { - const ei = await this.getLatestExecution(); - if (ei && ei.blockHash !== this.latestBlockHash) { - this.latestBlockHash = ei.blockHash; - return await callback?.(ei); - } - } catch (e) { - console.error(e); - } + 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) { + this.latestBlockHash = ei.blockHash; + return await callback?.(ei); + } + } catch (e) { + console.error(e); + } + } + protected async getLatestExecution(): Promise { await this._sync(); const update = await this.options.optimisticUpdateCallback();