npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chimera-js

v0.1.17

Published

Javascript library to facilitate the use of the web workers api.

Downloads

24

Readme

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:

  • First you will need to add the library chimera-js into your JavaScript code:
  import Chimera from 'chimera-js';

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

  • The first one is to use the Chimera object to specify a object with all the functions that you want to run in parallel through the method exportToWorker. OBS: In version 0.1.17 you can't export arrow functions in a single line. You need to use the parentheses and the braces when using the method exportToWorker.
  const _fibonacci = (n) => {
    (n < 2) ? 1 : _fibonacci(n-2) + _fibonacci(n-1);
  };

  Chimera.exportToWorker({ fibonacci: _fibonacci }).then((worker) => {
    // Do your code here
  });
  • The other one is that you can use the Chimera object to specify another JavaScript file to run in parallel (Inside a web worker) through the method setWorker.
  Chimera.setWorker('./parallelExample.js').then((worker) => {
    // Do your code here
  });
  • Either way the executed method will return a Promise and the callback function executed by that promise will receive a object (worker) that you can use to call a function defined in the file parallelExample.js or a function defined in the object exported.
  Chimera.exportToWorker({ fibonacci: _fibonacci }).then((worker) => {
    // Do your code here
  });
  -------------------------------------------------------------
  Chimera.setWorker('./parallelExample.js').then((worker) => {
    worker.executeFibonacci(42);
  });
  • All functions of the code executed in parallel that have a return will return a Promise and the callback function executed by that promise will receive a parameter result that is the result returned by the executed function.
  Chimera.setWorker('./parallelExample.js').then((worker) => {
    worker.executeFibonacci(42).then(result => {
        console.log(result);
    });
  });
  • To specify what functions will be available in your main thread you need to specify in the JavaScript code executed in parallel (in that case in the parallelExample.js file) by adding the public functions of your JavaScript code in the object worker inside the object WorkerGlobalScope.
  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
  • src: Source code of the library, with its main modules (Chimera, Meruem, Neferpitou)
  • test: The unit tests utils
  • package.json: The project dependecies and scripts
  • webpack.prod.config: The webpack configuration for transpile the source code
  • .eslintrc.json: The rulos of linting
  • .travis.yml: The configuration of Travis our CI tool

Inside the SRC folder

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

  • index.js: End-point and modules export
  • chimera.js: Main module to expose chimera-js API methods
  • meruem.js: Module responsible for create and manage the worker object that is created by chimera-js and runned in the web worker
  • neferpitou.worker.js: Default web worker that runs the parallel code and expose public functions to be used in the main thread. That one talks with meruem.js through the chimeraWorker object.