Skip to content

Instantly share code, notes, and snippets.

@amazzalel-habib
Created May 12, 2020 03:37
Show Gist options
  • Save amazzalel-habib/634dea56b123c26e328277ee5168c8aa to your computer and use it in GitHub Desktop.
Save amazzalel-habib/634dea56b123c26e328277ee5168c8aa to your computer and use it in GitHub Desktop.
import * as monaco from "monaco-editor-core";
import Uri = monaco.Uri;
import { TodoLangWorker } from './todoLangWorker';
import { languageID } from './config';
export class WorkerManager {
private worker: monaco.editor.MonacoWebWorker<TodoLangWorker>;
private workerClientProxy: Promise<TodoLangWorker>;
constructor() {
this.worker = null;
}
private getClientproxy(): Promise<TodoLangWorker> {
if (!this.workerClientProxy) {
this.worker = monaco.editor.createWebWorker<TodoLangWorker>({
// module that exports the create() method and returns a `JSONWorker` instance
moduleId: 'TodoLangWorker',
label: languageID,
// passed in to the create() method
createData: {
languageId: languageID,
}
});
this.workerClientProxy = <Promise<TodoLangWorker>><any>this.worker.getProxy();
}
return this.workerClientProxy;
}
async getLanguageServiceWorker(...resources: Uri[]): Promise<TodoLangWorker> {
const _client: TodoLangWorker = await this.getClientproxy();
await this.worker.withSyncedResources(resources)
return _client;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment