andywer / andywer/threads.js

What is the correct way to terminate a worker via Thread and BlobWorker?

未关闭
#491 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
3.5k
派生
173
PR 合并指标
30 天内没有已合并 PR

描述

I instantiate a worker:

```
import { spawn, Thread, BlobWorker } from 'threads';
import MyWorkerWeb from 'raw-loader!../dist/worker.js';

let worker = spawn(BlobWorker.fromText(MyWorkerWeb));

//
// do stuff with worker
// ...
```

When I am done with the worker, I would like to terminate it to remove it from memory and from the list of dedicated workers in the Task Manager:

```
Thread.terminate(worker);
```

This line of code returns the following error:

```
thread[symbols_1.$terminate] is not a function
TypeError: thread[symbols_1.$terminate] is not a function
at Object.terminate (http://localhost:3000/static/js/src_App_js-data_image_svg_xml_3csvg_xmlns_27http_www_w3_org_2000_svg_27_viewBox_27-4_-4_8_8_2-577bb7.chunk.js:28287:48)
```

Is there a correct way to terminate this worker, which does not require reloading the document (web page)?

Thanks for your advice.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。