Skip to content

Commit d884ad1

Browse files
committed
fix @mainsail/api-sync
1 parent 5890402 commit d884ad1

2 files changed

Lines changed: 19 additions & 23 deletions

File tree

packages/api-sync/source/listeners/abstract-listener.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export abstract class AbstractListener<TEventData, TEntity extends object> imple
6060
} catch (ex) {
6161
this.logger.error(`#syncToDatabaseTransaction failed: ${ex}`);
6262
} finally {
63-
this.#syncTimeout = setTimeout(run, syncInterval);
63+
this.#syncTimeout = setTimeout(() => {
64+
void run();
65+
}, syncInterval);
6466
}
6567
};
6668

packages/api-sync/source/tokens/whitelist.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,32 @@ export class TokenWhitelist {
3131
@inject(Identifiers.Cryptography.Identity.Address.Factory)
3232
private readonly addressFactory!: Contracts.Crypto.AddressFactory;
3333

34-
#syncInterval?: NodeJS.Timeout;
34+
#syncTimeout?: NodeJS.Timeout;
3535

3636
public async bootstrap(): Promise<void> {
3737
const syncInterval = this.#getTokenWhitelistRefreshIntervalMs();
3838

39-
let running = false;
40-
4139
this.logger.info(`Starting TokenWhitelist using remote: ${this.#getTokenWhitelistRemoteUrl()}`);
4240

43-
this.#syncWhitelist()
44-
.catch((error) => this.logger.error(`#syncWhitelist failed: ${error}`))
45-
.finally(() => {
46-
this.#syncInterval = setInterval(async () => {
47-
if (running) {
48-
return;
49-
}
50-
51-
running = true;
52-
53-
try {
54-
await this.#syncWhitelist();
55-
} catch (ex) {
56-
this.logger.error(`#syncWhitelist failed: ${ex}`);
57-
} finally {
58-
running = false;
59-
}
41+
const run = async () => {
42+
try {
43+
await this.#syncWhitelist();
44+
} catch (ex) {
45+
this.logger.error(`#syncWhitelist failed: ${ex}`);
46+
} finally {
47+
this.#syncTimeout = setTimeout(() => {
48+
void run();
6049
}, syncInterval);
61-
});
50+
}
51+
};
52+
53+
void run();
6254
}
6355

6456
public async dispose(): Promise<void> {
65-
clearInterval(this.#syncInterval);
57+
if (this.#syncTimeout) {
58+
clearTimeout(this.#syncTimeout);
59+
}
6660
}
6761

6862
async #syncWhitelist(): Promise<void> {

0 commit comments

Comments
 (0)