refactor: split subscribe into syncToLatestBlock
This commit is contained in:
parent
4836ddb32e
commit
11791ff08b
|
@ -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> {
|
||||
|
|
Loading…
Reference in New Issue