An open API service indexing awesome lists of open source software.

https://github.com/skitsanos/demo-worker-runner

Demo on how to use worker_threads Node.js feature
https://github.com/skitsanos/demo-worker-runner

js task-runner worker workers

Last synced: 7 months ago
JSON representation

Demo on how to use worker_threads Node.js feature

Awesome Lists containing this project

README

          

Just an example of how to use worker_threads in Node.js

---

Adding array of workers to be executed:

```js
const rawTasks = Array.from({length: 10}, (_, id) => ({
path: './downloadFile',
workerData: {options: {id}, url: `url...#${id}`}
}));

for (const worker of rawTasks)
{
WorkerRunner.add(worker);
}
```

Adding Async worker:

```js
WorkerRunner.add({
path: './downloadFileAsync',
workerData: {
url: 'https://api.skitsanos.com/api/utils/headers'
}
});
```

Tracking completion of the worker

```js
WorkerRunner.onTaskComplete = worker => console.log(worker);
```

Executing workers

```js
WorkerRunner.execute()
.then(console.log);
```