From f997d2c3ecb64a229e070c05ff3991be34206e17 Mon Sep 17 00:00:00 2001 From: Marcello Urbani Date: Sat, 21 Oct 2023 14:22:14 +0300 Subject: [PATCH] wait to avoid race condition --- .vscode/settings.json | 9 ++++++++- client/src/flows.ts | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 18ccc6d9..7ffd3525 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,12 @@ }, "typescript.tsdk": "./node_modules/typescript/lib", "typescript.tsc.autoDetect": "off", - "npm.exclude": ["**/client", "**/server"] + "npm.exclude": [ + "**/client", + "**/server" + ], + "files.watcherExclude": { + "**/node_modules/*/**": false, + "**/node_modules/[!@]*/**/*": true + } } \ No newline at end of file diff --git a/client/src/flows.ts b/client/src/flows.ts index 917b5a03..a056066b 100644 --- a/client/src/flows.ts +++ b/client/src/flows.ts @@ -34,6 +34,7 @@ export class Flows { const path = editor.document.uri.path.replace(/\.[^\.]*/, "").replace(/.*\//, ""); const uri = vscode.Uri.parse(`${ABAPLINTSCHEME}:${path}.dot`); setDocument(uri, "Loading"); + const startTime = new Date().getTime(); const doc = await vscode.workspace.openTextDocument(uri); await vscode.window.showTextDocument(doc, {preview: false, viewColumn: vscode.ViewColumn.Beside}); @@ -41,8 +42,13 @@ export class Flows { await this.pending; } this.pending = new Promise((resolve) => { - this.emitter.event((content) => { + const disposable = this.emitter.event(async (content) => { + disposable.dispose(); const contents = JSON.parse(content).join("\n\n"); + const dt = new Date().getTime() - startTime; + if (dt < 500) { + await new Promise((resolve) => setTimeout(resolve, 500 - dt)); + } setDocument(uri, contents); this.pending = undefined; resolve();