Skip to content

Commit ee34476

Browse files
authored
Merge pull request #1305 from mathjax/fix/stop-worker
Only stop the worker if it has been started
2 parents a6ec3c5 + b7be4a8 commit ee34476

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

ts/a11y/speech.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export function SpeechMathDocumentMixin<
316316
* @override
317317
*/
318318
public async done() {
319-
await this.webworker.Stop();
319+
await this.webworker?.Stop();
320320
return super.done();
321321
}
322322
};

ts/a11y/speech/WebWorker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,10 @@ export class WorkerHandler<N, T, D> {
468468

469469
/**
470470
* Terminates the worker.
471+
*
472+
* @returns {Promise<any>} The promise for the worker termination.
471473
*/
472-
public Terminate() {
474+
public Terminate(): Promise<any> | void {
473475
this.debug('Terminating pending tasks');
474476
for (const task of this.tasks) {
475477
task.reject(
@@ -478,18 +480,18 @@ export class WorkerHandler<N, T, D> {
478480
}
479481
this.tasks = [];
480482
this.debug('Terminating worker');
481-
this.worker.terminate();
483+
return this.worker.terminate();
482484
}
483485

484486
/**
485487
* Stop the worker and clear the values so that the worker can be
486488
* restarted, if desired.
487489
*/
488-
public Stop() {
490+
public async Stop() {
489491
if (!this.worker) {
490492
throw Error('Worker has not been started');
491493
}
492-
this.Terminate();
494+
await this.Terminate();
493495
this.worker = null;
494496
this.ready = false;
495497
}

ts/core/DOMAdaptor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export type PageBBox = {
4747
export interface minWorker {
4848
addEventListener(kind: string, listener: (event: Event) => void): void;
4949
postMessage(msg: any): void;
50-
terminate(): void;
50+
terminate(): Promise<any> | void;
5151
}
5252

5353
/*****************************************************************/

0 commit comments

Comments
 (0)