Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 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 (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T09:46:00.000Z (3 months ago)
- Last Synced: 2024-10-06T11:41:01.790Z (3 months ago)
- Topics: cross-platform, nodeworker, webworker, worker, worker-threads
- Language: TypeScript
- Size: 898 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# anyworker
[![](https://github.com/shilangyu/anyworker/workflows/ci/badge.svg)](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()
```