mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Changes for PR #30
This commit is contained in:
parent
6c73d7f708
commit
6b2271c1c1
9 changed files with 128 additions and 181 deletions
|
|
@ -17,6 +17,8 @@ export class WorkerManager {
|
|||
private _idleCheckInterval: number;
|
||||
private _lastUsedTime: number;
|
||||
private _configChangeListener: IDisposable;
|
||||
private _updateExtraLibsToken: number;
|
||||
private _extraLibsChangeListener: IDisposable;
|
||||
|
||||
private _worker: monaco.editor.MonacoWebWorker<TypeScriptWorker>;
|
||||
private _client: Promise<TypeScriptWorker>;
|
||||
|
|
@ -28,6 +30,8 @@ export class WorkerManager {
|
|||
this._idleCheckInterval = setInterval(() => this._checkIfIdle(), 30 * 1000);
|
||||
this._lastUsedTime = 0;
|
||||
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
|
||||
this._updateExtraLibsToken = 0;
|
||||
this._extraLibsChangeListener = this._defaults.onDidExtraLibsChange(() => this._updateExtraLibs());
|
||||
}
|
||||
|
||||
private _stopWorker(): void {
|
||||
|
|
@ -41,9 +45,23 @@ export class WorkerManager {
|
|||
dispose(): void {
|
||||
clearInterval(this._idleCheckInterval);
|
||||
this._configChangeListener.dispose();
|
||||
this._extraLibsChangeListener.dispose();
|
||||
this._stopWorker();
|
||||
}
|
||||
|
||||
private async _updateExtraLibs(): Promise<void> {
|
||||
if (!this._worker) {
|
||||
return;
|
||||
}
|
||||
const myToken = ++this._updateExtraLibsToken;
|
||||
const proxy = await this._worker.getProxy();
|
||||
if (this._updateExtraLibsToken !== myToken) {
|
||||
// avoid multiple calls
|
||||
return;
|
||||
}
|
||||
proxy.updateExtraLibs(this._defaults.getExtraLibs());
|
||||
}
|
||||
|
||||
private _checkIfIdle(): void {
|
||||
if (!this._worker) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue