All Projects → webosorg → Process

webosorg / Process

Licence: MIT License
Creation of Dynamic Dedicated WebWorkers, definition of dependencies, promise support.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to Process

Thread
type safe multi-threading made easier
Stars: ✭ 34 (+161.54%)
Mutual labels:  thread, webworkers
event-worker
A simpler way of dealing with Web Workers
Stars: ✭ 18 (+38.46%)
Mutual labels:  thread, process
tgrid
TypeScript Grid Computing Framework supporting RFC (Remote Function Call)
Stars: ✭ 83 (+538.46%)
Mutual labels:  thread, process
jellex
TUI to filter JSON and JSON Lines data with Python syntax
Stars: ✭ 41 (+215.38%)
Mutual labels:  process
CPU-MEM-monitor
A simple script to log Linux CPU and memory usage (using top or pidstat command) over time and output an Excel- or OpenOfficeCalc-friendly report
Stars: ✭ 41 (+215.38%)
Mutual labels:  thread
DLL-Injector
Inject and detour DLLs and program functions both managed and unmanaged in other programs, written (almost) purely in C#. [Not maintained].
Stars: ✭ 29 (+123.08%)
Mutual labels:  process
codebase
The jBPT code library is a compendium of technologies that support research on design, execution, and evaluation of business processes. The library offers a broad range of basis analysis and utility functionality and, due to its open publishing model, can easily be extended.
Stars: ✭ 26 (+100%)
Mutual labels:  process
Steam-Apps-Management-API
A basic Steam Application Management API and Valve Data Format (VDF) reader/writer.
Stars: ✭ 24 (+84.62%)
Mutual labels:  process
PRUNE
Logs key Windows process performance metrics. #nsacyber
Stars: ✭ 56 (+330.77%)
Mutual labels:  process
fastthreadpool
An efficient and lightweight thread pool
Stars: ✭ 27 (+107.69%)
Mutual labels:  thread
CS302-Operating-System
OS course of SUSTech
Stars: ✭ 18 (+38.46%)
Mutual labels:  thread
prox
A Scala library for working with system processes
Stars: ✭ 93 (+615.38%)
Mutual labels:  process
bangle-io
A web only WYSIWYG note taking app that saves notes locally in markdown format.
Stars: ✭ 626 (+4715.38%)
Mutual labels:  webworkers
jobflow
runs stuff in parallel (like GNU parallel, but much faster and memory-efficient)
Stars: ✭ 67 (+415.38%)
Mutual labels:  process
AsyncUtils
A set of utilities for Asynchronous programming in Unity.
Stars: ✭ 15 (+15.38%)
Mutual labels:  thread
unshare
The low-level linux containers creation library for rust
Stars: ✭ 99 (+661.54%)
Mutual labels:  process
LockFreeHashTable
Lock Free Resizable Hash Table Based On Split-Ordered Lists.
Stars: ✭ 45 (+246.15%)
Mutual labels:  thread
URL-Magnet-Cloud-Uploader-Heroku
Aria 2 Rclone Remote URL /magnet Clouds upload via HEROKU
Stars: ✭ 99 (+661.54%)
Mutual labels:  thread
kill-process
Bash script to kill high CPU process, long running process and too much consuming memory process.
Stars: ✭ 58 (+346.15%)
Mutual labels:  process
awesome-dotnet-async
A curated list of awesome articles and resources to learning and practicing about async, threading, and channels in .Net platform. 😉
Stars: ✭ 84 (+546.15%)
Mutual labels:  thread

@webos/process

(a histogram of downloads)

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.log('Hello world');

in other thread, we can do this in two ways:

  1. Create a new file myWorker.js which will contain the code
console.log('Hello World');

and then call it from the main thread by writing

const myWorker = new Worker('./myWorker.js');
  1. Or if we want to create it in a dynamic way, we can write:
const source = 'console.log("Hello world")';

const blob = new Blob([source], {type: 'application/javascript'});

const myWorker = new Worker(URL.createObjectURL(blob));

@webos/process lets us create dynamic workers, 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:

import Process from '@webos/process';

const process = new Process();

process
  .setSource(
    num => num ** 2
  )
  .postMessage(12)
  .then(
    result => console.log('Log ::: Result ::: ', result)
  );

@webos/process also allows to define dependencies for workers

import Process from '@webos/process';

const process = new Process;

process
  .setSource(
    arr => _.sortBy(arr),
    ['https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js']
  )
  .postMessage([3, 2, 0, 1])
  .then(
    result => console.log('Log ::: Result ::: ', result)
  );

Also, you can pass a string to .setSrouce method as a source; in that case, you also need to pass the function name (which is going to be executed from source as a final function) as a third parameter. For example:

import Process from '@webos/process';

const process = new Process;

process
  .setSource(
    `
      const fibs = {};

      function fib(n) {
        if (n < 2) {
          return n;
        } else {
          if (!((n - 1) in fibs)) {
            fibs[n - 1] = fib(n - 1);
          }
          if (!((n - 2) in fibs)) {
            fibs[n - 2] = fib(n -2);
          }
          return fibs[n - 1] + fibs[n - 2];
        }
      }

      function anotherFunction(x) { return x + 1 }

      const oneMoreFunction = opt => { //... }
    `,
    [],
    'fib' // we want to "work" exactly with 'fib' function
  )
  .postMessage(14)
  .then(
    result => console.log('Log ::: Result ::: ', result)
  );

Install

(npm package version)

Install for usage

Latest packaged version

npm i @webos/process

or

yarn add @webos/process

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 @webos/process
import Process from '@webos/process';

// Create a new process

const process = new Process;

process
  // set source (fn and deps)
  .setSource(
    num => num ** 2
  )
  // send data for calculation
  .postMessage(12)
  // get result
  .then(
    result => console.log('Log ::: Result ::: ', result)
  );

With dependencies

// Import @webos/process
import Process from '@webos/process';

// Create a new process
const process = new Process;

process
  // set source (fn and deps)
  .setSource(
    // fn
    arr => _.sortBy(arr),
    // array of dependencies
    ['https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js']
  )
  // send data for calculation
  .postMessage([3, 2, 0, 1])
  // get result
  .then(
    result => console.log('Log ::: Result ::: ', result)
  );

Full Promise support

const process_01 = new Process;

const process_02 = new Process;

const calc_01 = process_01.setSource(arr => arr.sort(arr));

const calc_02 = process_01.setSource(num => num ** 2);

const calc_03 = process_02.setSource(
  arr => _.sortBy(arr),
  ['https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js']
);

Promise.all(
  [
    calc_01.postMessage([3, 1, 2]),
    calc_02.postMessage(12),
    calc_03.postMessage(['x', 'y', 'z', 'a', 123])
  ]
)
.then(result => {
  process_01.kill();
  process_02.kill();
  console.log('Log ::: Result ::: ', result);
});

License

MIT licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].