parallel-es
TypeScript icon, indicating that this package has built-in type declarations

0.1.18 • Public • Published

parallel.es

Build Status Coverage Status npm version

A JavaScript library to perform parallel JavaScript computations with ease (and other environments soon).

Getting Started

Install Parallel.es using npm:

npm install --save parallel-es

or yarn:

yarn add parallel-es

Performing a single computation in a background thread is as simple as calling a normal method:

import parallel from "parallel-es";
 
parallel.run(function () {
    //… compute
    return [1, 2, 3];
}).then(result => console.log(result));

Or use the reactive API to parallelize data stream based operations. The reactive API automatically splits the input array into sub-arrays, computes the sub-results in a web worker, and joins the resulting arrays:

parallel.range(0, 100000)
    .map(value => value * value)
    .then(result => console.log(result));

To show a progress update, use the subscribe method to register a callback that is invoked whenever a sub-result has been computed:

parallel.range(0, 100000)
    .map(value => value * value)
    .subscribe((subresult, taskIndex) => console.log(`The result of the task ${taskIndex} is`, subresult);)
    .then(result => console.log(result));

For more detail, take a look at the API Documentation.

Debugging Support

Parallel.es uses function serialization and, therefore, debugging is not supported out of the box (except if the debugger statement is used. However, there is a webpack plugin that transpiles the program code and generates the needed source maps to enable debugging (at least in Chrome and Firefox Nightly).

Referenced Functions, Variables, and Imports

Parallel.es uses function serialization and, therefore, the variables from the closure (outer scope) are no longer available when the function is invoked in the background thread. However, there is a webpack plugin that rewrites your code and allows you to use constant variables, and as well, functions defined in the outer scope of the task function. The plugin also exposes any used imports in the background thread.

Documentation

The API Documentation is available online. The wiki describes the architecture in more detail. An academical description of the work is available here.

Examples

An example project using parallel-es and comparing its performance to related projects is parallel-es-example. The examples are hosted here.

Browsers support made by @godban

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
Opera
Opera
iOS Safari
iOS Safari
Chrome for Android
Android
IE10, IE11, Edge last 2 versions last 2 versions last 2 versions last 2 versions iOS 5.1, iOS 6, iOS 7, iOS 8, iOS 9 Chrome, Android 4.4

Automated browser testing is performed using BrowserStack's open source offer.

BrowserStack

Related Work

There exist other runtime systems with identical or similar goals. The report of the project thesis compares these runtime systems concerning applicability and runtime performance.

Package Sidebar

Install

npm i parallel-es

Weekly Downloads

0

Version

0.1.18

License

MIT

Last publish

Collaborators

  • datenmetzgerx