andywer / andywer/threads.js

Support (async) generator functions

Đang mở
#251 2 bình luận 1 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
TypeScript
Star
3.5k
Fork
173
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I think it would be great if the observer pattern described [here](https://threads.js.org/usage-observables) can be written as follows so that we do not have to depend on any observable libraries but ECMAScript standards.

```js
// master.js
import { spawn, Thread, Worker } from "threads"

const counter = await spawn(new Worker("./workers/counter"))

for await (const newCount of counter()) {
console.log(`Counter incremented to:`, newCount)
}
```

```js
// workers/counter.js
import { expose } from "threads/worker"

function* startCounting() { // async generator function should also be OK
for (let currentCount = 1; currentCount <= 10; currentCount++) {
yield currentCount;
}
}

expose(startCounting)
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.