andywer / andywer/threads.js

Support (async) generator functions

Abierto
#251 2 comentarios 1 reacción 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
TypeScript
Estrellas
3.5k
Forks
173
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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)
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.