Merge pull request #109 from patrickshipe/restore-options-updates

Restore ability to change options after loading
This commit is contained in:
Remco Haszing 2021-09-15 21:52:57 +02:00 committed by GitHub
commit 65e91a1d43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,18 +13,27 @@ export function createWorkerManager(
let client: Promise<YAMLWorker>;
let lastUsedTime = 0;
const stopWorker = (): void => {
if (worker) {
worker.dispose();
worker = undefined;
}
client = undefined;
};
setInterval(() => {
if (!worker) {
return;
}
const timePassedSinceLastUsed = Date.now() - lastUsedTime;
if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
worker.dispose();
worker = undefined;
client = undefined;
stopWorker();
}
}, 30 * 1000);
// This is necessary to have updated language options take effect (e.g. schema changes)
defaults.onDidChange(() => stopWorker());
const getClient = (): Promise<YAMLWorker> => {
lastUsedTime = Date.now();