diff --git a/ts/a11y/speech.ts b/ts/a11y/speech.ts index e7ceae9c2..7f4b5423d 100644 --- a/ts/a11y/speech.ts +++ b/ts/a11y/speech.ts @@ -316,7 +316,7 @@ export function SpeechMathDocumentMixin< * @override */ public async done() { - await this.webworker.Stop(); + await this.webworker?.Stop(); return super.done(); } }; diff --git a/ts/a11y/speech/WebWorker.ts b/ts/a11y/speech/WebWorker.ts index 5e73867c5..d86c61fe8 100644 --- a/ts/a11y/speech/WebWorker.ts +++ b/ts/a11y/speech/WebWorker.ts @@ -468,8 +468,10 @@ export class WorkerHandler { /** * Terminates the worker. + * + * @returns {Promise} The promise for the worker termination. */ - public Terminate() { + public Terminate(): Promise | void { this.debug('Terminating pending tasks'); for (const task of this.tasks) { task.reject( @@ -478,18 +480,18 @@ export class WorkerHandler { } this.tasks = []; this.debug('Terminating worker'); - this.worker.terminate(); + return this.worker.terminate(); } /** * Stop the worker and clear the values so that the worker can be * restarted, if desired. */ - public Stop() { + public async Stop() { if (!this.worker) { throw Error('Worker has not been started'); } - this.Terminate(); + await this.Terminate(); this.worker = null; this.ready = false; } diff --git a/ts/core/DOMAdaptor.ts b/ts/core/DOMAdaptor.ts index 27486b6a7..16889ddcb 100644 --- a/ts/core/DOMAdaptor.ts +++ b/ts/core/DOMAdaptor.ts @@ -47,7 +47,7 @@ export type PageBBox = { export interface minWorker { addEventListener(kind: string, listener: (event: Event) => void): void; postMessage(msg: any): void; - terminate(): void; + terminate(): Promise | void; } /*****************************************************************/