whortaneto / chimera-js

Javascript library to facilitate the use of the web workers api.
MIT License
4 stars 0 forks source link

chimera-js

Build Status Coverage Status

What Is This?

(In development)

This is a open source JavaScript library that seeks to help developers by simplifying the use of Web Workers API.

Examples

We have a example project on github ChimeraJSPOC.

But basically, here is where you can get started:

  import Chimera from 'chimera-js';

We have two ways to use a parallel web worker using chimera-js;

  const _fibonacci = (n) => {
    (n < 2) ? 1 : _fibonacci(n-2) + _fibonacci(n-1);
  };

  Chimera.exportToWorker({ fibonacci: _fibonacci }).then((worker) => {
    // Do your code here
  });
  Chimera.setWorker('./parallelExample.js').then((worker) => {
    // Do your code here
  });
  Chimera.exportToWorker({ fibonacci: _fibonacci }).then((worker) => {
    // Do your code here
  });
  -------------------------------------------------------------
  Chimera.setWorker('./parallelExample.js').then((worker) => {
    worker.executeFibonacci(42);
  });
  Chimera.setWorker('./parallelExample.js').then((worker) => {
    worker.executeFibonacci(42).then(result => {
        console.log(result);
    });
  });
  const _fibonacci = n => (n < 2) ? 1 : _fibonacci(n-2) + _fibonacci(n-1);

  WorkerGlobalScope.chimeraWorker = {
    executeFibonacci: _fibonacci
  }

This example will calculate the fibonacci of 42, process which normally blocks the JavaScript main thread and all it DOM, but thanks to the power of Web Workers that will not happen and thanks to the API of the library chimera-js we developers can do that in a much easier way.

Project structure

The files of the project

When you clone or download the project you will see the following files:

src/
test/
package.json
webpack.config.js
.eslintrc.json
.travis.yml

Inside the SRC folder

The files inside the src folder are structured in that way: