https://github.com/shilangyu/anyworker
Stop worrying about your Worker's environment
https://github.com/shilangyu/anyworker
cross-platform nodeworker webworker worker worker-threads
Last synced: about 2 months ago
JSON representation
Stop worrying about your Worker's environment
- Host: GitHub
- URL: https://github.com/shilangyu/anyworker
- Owner: shilangyu
- License: mit
- Created: 2019-05-11T09:39:27.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-01T12:31:29.000Z (4 months ago)
- Last Synced: 2025-03-29T08:32:58.221Z (3 months ago)
- Topics: cross-platform, nodeworker, webworker, worker, worker-threads
- Language: TypeScript
- Size: 543 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# anyworker
[](https://github.com/shilangyu/anyworker/actions)
```
npm i anyworker
```Creates a bridge between web's WebWorker and node's worker_threads.
No more writing duplicate code for node and web targets ✨
Implements:
- postMessage
- onerror
- onmessage
- terminateAdditionally gives such APIs as:
- restart
## example
```ts
import Worker from 'anyworker'const worker = new Worker(() => {
postMessage({ sending: ['a', 'message', 'from', 'worker'] })onmessage(data => console.log('hello from a worker! Master sent me:', data))
})worker.postMessage({ sending: ['a', 'message', 'from', 'master'] })
worker.onmessage(data => console.log('hello from master! Worker sent me:', data))// later
worker.terminate()
// or
worker.restart()
```