Pass abortSignal to sendToGroup

This commit is contained in:
Fedor Indutny 2022-05-23 15:08:13 -07:00 committed by GitHub
parent 7afe3fcca2
commit 3be95e821e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 26 deletions

View file

@ -3440,7 +3440,10 @@ export class ConversationModel extends window.Backbone
return null;
}
queueJob<T>(name: string, callback: () => Promise<T>): Promise<T> {
queueJob<T>(
name: string,
callback: (abortSignal: AbortSignal) => Promise<T>
): Promise<T> {
this.jobQueue = this.jobQueue || new window.PQueue({ concurrency: 1 });
const taskWithTimeout = createTaskWithTimeout(
@ -3448,6 +3451,9 @@ export class ConversationModel extends window.Backbone
`conversation ${this.idForLogging()}`
);
const abortController = new AbortController();
const { signal: abortSignal } = abortController;
const queuedAt = Date.now();
return this.jobQueue.add(async () => {
const startedAt = Date.now();
@ -3458,7 +3464,10 @@ export class ConversationModel extends window.Backbone
}
try {
return await taskWithTimeout();
return await taskWithTimeout(abortSignal);
} catch (error) {
abortController.abort();
throw error;
} finally {
const duration = Date.now() - startedAt;