Created
May 12, 2020 03:37
-
-
Save amazzalel-habib/634dea56b123c26e328277ee5168c8aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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