Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joh/eastern slug #190250

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/vs/base/browser/defaultWorkerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { createTrustedTypesPolicy } from 'vs/base/browser/trustedTypes';
import { onUnexpectedError } from 'vs/base/common/errors';
import { COI } from 'vs/base/common/network';
import { IWorker, IWorkerCallback, IWorkerFactory, logOnceWebWorkerWarning } from 'vs/base/common/worker/simpleWorker';

Expand Down Expand Up @@ -85,11 +86,13 @@ function isPromiseLike<T>(obj: any): obj is PromiseLike<T> {
*/
class WebWorker implements IWorker {

private id: number;
private readonly id: number;
private readonly label: string;
private worker: Promise<Worker> | null;

constructor(moduleId: string, id: number, label: string, onMessageCallback: IWorkerCallback, onErrorCallback: (err: any) => void) {
this.id = id;
this.label = label;
const workerOrPromise = getWorker(label);
if (isPromiseLike(workerOrPromise)) {
this.worker = workerOrPromise;
Expand All @@ -113,7 +116,14 @@ class WebWorker implements IWorker {
}

public postMessage(message: any, transfer: Transferable[]): void {
this.worker?.then(w => w.postMessage(message, transfer));
this.worker?.then(w => {
try {
w.postMessage(message, transfer);
} catch (err) {
onUnexpectedError(err);
onUnexpectedError(new Error(`FAILED to post message to '${this.label}'-worker`, { cause: err }));
}
});
}

public dispose(): void {
Expand Down