This commit is contained in:
Dirk Baeumer 2024-05-27 19:29:08 +02:00
Родитель b4620b3ff0
Коммит be84fa75a0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: DD95715335E91385
1 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -18,7 +18,25 @@ The examples require that you have the latest versions of the following tools in
All the examples provided in the previous blog post executed the WebAssembly code inside VS Code's extension host main thread. This is fine as long as the execution time is short. However, long-running operations should be executed in a worker to ensure that the extension host main thread remains available for other extensions.
Doing so is quite easy since VS Code's component model implementation provides a meta model that allows us to generate all the necessary glue code on the worker side automatically.
Doing so is quite easy since VS Code's component model implementation provides a meta model that allows us to generate all the necessary glue code on the worker and extension main side automatically.
Below, the code necessary for the worker. The example assumes that the code is store in a file names `worker.ts`
```typescript
import { Connection, RAL } from '@vscode/wasm-component-model';
import { calculator } from './calculator';
async function main(): Promise<void> {
const connection = await Connection.createWorker(calculator._);
connection.listen()
};
main().catch(RAL().console.error);
```
All the code does is to create a connection to talk to the extension host main worker and initialize the connection with the `calculator` world generate by the `wit2ts` tool.
On the extension side all we need to do
```typescript
/// Still needs to be inserted. Polishing the way how this works.