未验证 提交 9b4316b8 编写于 作者: A Alexandru Dima 提交者: GitHub

Merge pull request #46032 from fathyb/feat/get-worker

Add getWorker to MonacoEnvironment
......@@ -7,17 +7,22 @@
import { globals } from 'vs/base/common/platform';
import { logOnceWebWorkerWarning, IWorker, IWorkerCallback, IWorkerFactory } from 'vs/base/common/worker/simpleWorker';
function getWorkerUrl(workerId: string, label: string): string {
// Option for hosts to overwrite the worker script url (used in the standalone editor)
if (globals.MonacoEnvironment && typeof globals.MonacoEnvironment.getWorkerUrl === 'function') {
return globals.MonacoEnvironment.getWorkerUrl(workerId, label);
function getWorker(workerId: string, label: string): Worker {
// Option for hosts to overwrite the worker script (used in the standalone editor)
if (globals.MonacoEnvironment) {
if (typeof globals.MonacoEnvironment.getWorker === 'function') {
return globals.MonacoEnvironment.getWorker(workerId, label);
}
if (typeof globals.MonacoEnvironment.getWorkerUrl === 'function') {
return new Worker(globals.MonacoEnvironment.getWorkerUrl(workerId, label));
}
}
// ESM-comment-begin
if (typeof require === 'function') {
return require.toUrl('./' + workerId) + '#' + label;
return new Worker(require.toUrl('./' + workerId) + '#' + label);
}
// ESM-comment-end
throw new Error(`You must define a function MonacoEnvironment.getWorkerUrl`);
throw new Error(`You must define a function MonacoEnvironment.getWorkerUrl or MonacoEnvironment.getWorker`);
}
/**
......@@ -31,7 +36,7 @@ class WebWorker implements IWorker {
constructor(moduleId: string, id: number, label: string, onMessageCallback: IWorkerCallback, onErrorCallback: (err: any) => void) {
this.id = id;
this.worker = new Worker(getWorkerUrl('workerMain.js', label));
this.worker = getWorker('workerMain.js', label);
this.postMessage(moduleId);
this.worker.onmessage = function (ev: any) {
onMessageCallback(ev.data);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册