mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-05 23:33:08 +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 isRunning: boolean = false;
|
||||||
private abortController?: AbortController;
|
private abortController?: AbortController;
|
||||||
|
private activeQueryPromise?: Promise<void>;
|
||||||
|
|
||||||
private boundStoreConnectHandler?: (event: CustomEvent<PeerId>) => void;
|
private boundStoreConnectHandler?: (event: CustomEvent<PeerId>) => void;
|
||||||
private boundHealthHandler?: (event: CustomEvent<HealthStatus>) => void;
|
private boundHealthHandler?: (event: CustomEvent<HealthStatus>) => void;
|
||||||
@ -87,7 +88,7 @@ export class QueryOnConnect<
|
|||||||
this.setupEventListeners();
|
this.setupEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop(): void {
|
public async stop(): Promise<void> {
|
||||||
if (!this.isRunning) {
|
if (!this.isRunning) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -99,6 +100,15 @@ export class QueryOnConnect<
|
|||||||
this.abortController = undefined;
|
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();
|
this.unsetEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +140,10 @@ export class QueryOnConnect<
|
|||||||
this.lastTimeOffline > this.lastSuccessfulQuery ||
|
this.lastTimeOffline > this.lastSuccessfulQuery ||
|
||||||
timeSinceLastQuery > this.forceQueryThresholdMs
|
timeSinceLastQuery > this.forceQueryThresholdMs
|
||||||
) {
|
) {
|
||||||
await this.query(peerId);
|
this.activeQueryPromise = this.query(peerId).finally(() => {
|
||||||
|
this.activeQueryPromise = undefined;
|
||||||
|
});
|
||||||
|
await this.activeQueryPromise;
|
||||||
} else {
|
} else {
|
||||||
log.info(`no querying`);
|
log.info(`no querying`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user