mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 13:53:12 +00:00
fix: add active query tracking to QueryOnConnect and await its stop()
This commit is contained in:
parent
9793b40275
commit
a97e7eceb9
@ -54,6 +54,7 @@ export class QueryOnConnect<
|
||||
|
||||
private isRunning: boolean = false;
|
||||
private abortController?: AbortController;
|
||||
private activeQueryPromise?: Promise<void>;
|
||||
|
||||
private boundStoreConnectHandler?: (event: CustomEvent<PeerId>) => void;
|
||||
private boundHealthHandler?: (event: CustomEvent<HealthStatus>) => void;
|
||||
@ -87,7 +88,7 @@ export class QueryOnConnect<
|
||||
this.setupEventListeners();
|
||||
}
|
||||
|
||||
public stop(): void {
|
||||
public async stop(): Promise<void> {
|
||||
if (!this.isRunning) {
|
||||
return;
|
||||
}
|
||||
@ -99,6 +100,15 @@ export class QueryOnConnect<
|
||||
this.abortController = undefined;
|
||||
}
|
||||
|
||||
if (this.activeQueryPromise) {
|
||||
log.info("Waiting for active query to complete...");
|
||||
try {
|
||||
await this.activeQueryPromise;
|
||||
} catch (error) {
|
||||
log.warn("Active query failed during stop:", error);
|
||||
}
|
||||
}
|
||||
|
||||
this.unsetEventListeners();
|
||||
}
|
||||
|
||||
@ -130,7 +140,10 @@ export class QueryOnConnect<
|
||||
this.lastTimeOffline > this.lastSuccessfulQuery ||
|
||||
timeSinceLastQuery > this.forceQueryThresholdMs
|
||||
) {
|
||||
await this.query(peerId);
|
||||
this.activeQueryPromise = this.query(peerId).finally(() => {
|
||||
this.activeQueryPromise = undefined;
|
||||
});
|
||||
await this.activeQueryPromise;
|
||||
} else {
|
||||
log.info(`no querying`);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user