jetworker easy way for community with WebWorker
Chrome | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|
4 | 3.5 | 10 | 10.6 | 4 |
Android | Chrome | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
4.4 | 4 | 3.5 | 10 | 11.5 | 5.1 |
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
const Client = require("jetworker/client");
//or
import Client from "jetworker/client";
const Service = require("jetworker/service");
//or
import Service from "jetworker/service";
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));
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);
You should use post
instead emit
inside client
- const { emit } = new Client("./worker.js");
+ const { post } = new Client("./worker.js");