Skip to content

Commit

Permalink
online_editor: Fix race condition while initializing the lsp worker
Browse files Browse the repository at this point in the history
  • Loading branch information
ogoffart committed Aug 24, 2022
1 parent 566e40c commit 6cdce8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tools/online_editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,19 @@ export Demo := Window {
type: "module",
}
);
// lsp_worker.onmessage
const reader = new BrowserMessageReader(lsp_worker);
const writer = new BrowserMessageWriter(lsp_worker);
lsp_worker.onmessage = m => {
// We cannot start sending messages to the client before we start listening which
// the server only does in a future after the wasm is loaded.
if (m.data === "OK") {

const languageClient = createLanguageClient({ reader, writer });
languageClient.start();
const reader = new BrowserMessageReader(lsp_worker);
const writer = new BrowserMessageWriter(lsp_worker);

reader.onClose(() => languageClient.stop());
const languageClient = createLanguageClient({ reader, writer });

languageClient.start();

reader.onClose(() => languageClient.stop());
}
}
})();
3 changes: 3 additions & 0 deletions tools/online_editor/src/worker/lsp_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ slint_init().then((_) => {

// Listen on the connection
connection.listen();

// Now that we listen, the client is ready to send the init message
self.postMessage("OK");
});

0 comments on commit 6cdce8b

Please sign in to comment.