Process-js
Synopsys
Creation of Dynamic Dedicated WebWorkers, definition of dependencies, promise support.
Motivation
Today we have an opportunity to run a js code in other threads in browsers by using web workers. Web workers give us new flexibility and opportunity for creating more complex js applications. But web workers' api may create complications in some cases: for example, when we want to run the following code:
console;
in other thread, we can do this in two ways:
- Create a new file myWorker.js which will contain the code
console;
and then call it from the main thread by writing
const myWorker = './myWorker.js';
- Or if we want to create it in a dynamic way, we can write:
const source = 'console.log("Hello world")'; const blob = source type: 'application/javascript'; const myWorker = URL;
process-js lets us create dynamic workers in main thread, use and manage them more comfortably and with promise support. There is no need to create a new file, also there is no need in onmessage or onerror callbacks, the latest will work with promise support. For example:
; const process = ; process ;
process-js also allows to define dependencies for workers
; const process = ; process ;
Install
Install for usage
Latest packaged version :::
npm i process-js
or
yarn add process-js
Latest version available in GitHub :::
npm i https://github.com/webosorg/Process
or
yarn add https://github.com/webosorg/Process
Install for development
git clone https://github.com/webosorg/Process.git
Usage
NOTE ::: In this stage it's only for browsers.
Simple usage
// Import process-js; // Create a new process const process = ; process // set source (fn and deps) // send data for calculation // get result ;
With dependencies
// Import process-js; // Create a new processconst process = ; process // set source (fn and deps) // send data for calculation // get result ;
Full Promise support
const process_01 = ; const process_02 = ; const calc_01 = process_01; const calc_02 = process_01; const calc_03 = process_02; Promiseall calc_01 calc_02 calc_03 ;
License
MIT