https://github.com/alex-mas/thread-manager
Thread manager builds on top of javascript WebWorkers to allow things such as middleware and work distribution.
https://github.com/alex-mas/thread-manager
multithreading webworkers
Last synced: 11 months ago
JSON representation
Thread manager builds on top of javascript WebWorkers to allow things such as middleware and work distribution.
- Host: GitHub
- URL: https://github.com/alex-mas/thread-manager
- Owner: alex-mas
- License: mit
- Created: 2018-06-10T19:26:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T19:47:20.000Z (about 3 years ago)
- Last Synced: 2025-02-12T11:07:56.722Z (11 months ago)
- Topics: multithreading, webworkers
- Language: TypeScript
- Homepage:
- Size: 1.33 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Thread Manager
> Library designed to facilitate orchestrating work across multiple WebWorkers
Thread manager offers the following features on top of the standard Web Workers API:
- Ability to spawn multiple workers and manage them with a simple api.
- Different work distribution methods to optimize the load across the pools of workers.
- Middleware system
# Usage
The package is packaged as umd so it can be added to your .html or included for webpack/rollup to handle
## Example
Check /tests/e2e folder for diferent examples, but a simple one would be:
```javascript
// This example sends 'Hello world' and the worker sends it back to the main script so that its printed
import {ThreadManager} from '@axc/thread-manager'
const TaskManager = new ThreadManager({src: './path/to/your/worker.js', config: {amount: 10}});
TaskManager.setMessageHandler = (e)=>{
console.log(e.data);
//yields 'Hello world'
}
//triggers setMessageHandler once
TaskManager.sendMessage('Hello World');
//triggers setMessageHandler ten times
TaskManager.broadcast('Hello World')
```
```javascript
// ./path/to/your/worker.js
onmessage = function (message) {
//some expensive computation
postMessage(message.data);
}
```
## Documentation
You can check the documentation [here](https://alex-mas.github.io/thread-manager/classes/_index_.threadmanager.html)
For more information, check [mdn Web Workers API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) since most functionality here just wraps what is ofered by the Worker and SharedWorker objects.