Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/behnammodi/jetworker
jetworker easy way for community with Web Worker
https://github.com/behnammodi/jetworker
javascript jetworker webworker
Last synced: 19 days ago
JSON representation
jetworker easy way for community with Web Worker
- Host: GitHub
- URL: https://github.com/behnammodi/jetworker
- Owner: behnammodi
- License: mit
- Created: 2018-12-09T12:30:26.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T04:48:17.000Z (over 1 year ago)
- Last Synced: 2024-05-21T15:33:21.521Z (6 months ago)
- Topics: javascript, jetworker, webworker
- Language: JavaScript
- Homepage:
- Size: 2.19 MB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## jetworker
[![NPM](https://nodei.co/npm/jetworker.png)](https://nodei.co/npm/jetworker/)
[![install size](https://packagephobia.now.sh/badge?p=jetworker)](https://packagephobia.now.sh/result?p=jetworker) [![dependencies](https://david-dm.org/uxitten/jetworker.svg)](https://david-dm.org/uxitten/jetworker.svg)
jetworker easy way for community with WebWorker
### Browser compatibility desktop
| Chrome | Firefox | Internet Explorer | Opera | Safari |
| ------ | ------- | ----------------- | ----- | ------ |
| 4 | 3.5 | 10 | 10.6 | 4 |### Browser compatibility mobile
| Android | Chrome | Firefox | Internet Explorer | Opera | Safari |
| ------- | ------ | ------- | ----------------- | ----- | ------ |
| 4.4 | 4 | 3.5 | 10 | 11.5 | 5.1 |## install
```npm
npm install jetworker --save
```jetwork has two section `Client` and `Service`
`Client` for use in main thread website or webapp
`Service` for use in WebWorker file
## import Client
```javascript
const Client = require("jetworker/client");
//or
import Client from "jetworker/client";
```## import Service
```javascript
const Service = require("jetworker/service");
//or
import Service from "jetworker/service";
```## use web
```javascript
import Client from "jetworker/client";const { post } = new Client("./worker.js");
/**
* post(name, data, callback)
* @param {string} name is function name in worker
* @param {any} data send to worker
* @param {function} callback for recive response from worker
* @returns {undefined} nothing
*/
post("multiple", { a: 2, b: 3 }, result => console.log(result));
```## in worker.js
```javascript
import Service from "jetworker/service";const { on } = new Service();
function multiple(data, response) {
response(data.a * data.b);
}/**
* service.on(name, process)
* @param {string} name function name for call in client
* @param {function} process function, data is data recived from client and post is function for send result to client
*/
on("multiple", multiple);
```## Migration from v1 to v2
You should use `post` instead `emit` inside client
```diff
- const { emit } = new Client("./worker.js");
+ const { post } = new Client("./worker.js");
```