Giter Site home page Giter Site logo

iamnitheeshm / microjob Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wilk/microjob

1.0 1.0 0.0 2 MB

A tiny wrapper for turning Node.js worker threads into easy-to-use routines for heavy CPU loads.

Home Page: https://wilk.github.io/microjob/

License: MIT License

TypeScript 100.00%

microjob's Introduction

Microjob

npm version Build Status Coverage Status Dependencies

A tiny wrapper for turning Node.js threads in easy-to-use routines for CPU-bound.

Introduction

Microjob is a tiny wrapper for Node.js threads and is intended to perform heavy CPU loads using anonymous functions.

So, Microjob treats Node.js threads as temporary working units: if you need to spawn a long-living thread, then you should use the default API.

From version v0.1.0 microjob uses a Worker Pool ๐ŸŽ‰

Microjob follows the same line of the original Node.js documentation: use it only for CPU-bound jobs and not for I/O-bound purposes. Quoting the documentation:

Workers are useful for performing CPU-intensive JavaScript operations; do not use them for I/O, since Node.jsโ€™s built-in mechanisms for performing operations asynchronously already treat it more efficiently than Worker threads can.

Microjob can be used with Node.js 12+ without flag. With Node.js 10.5+ you need the --experimental-worker flag activated, otherwise it won't work.

More details explained in: Microjob: a tiny multithreading library for Node.js

Installation

Via npm:

$ npm install --save microjob

Quick Example

(async () => {
  const { job, start, stop } = require("microjob");

  try {
    // start the worker pool
    await start();

    // this function will be executed in another thread
    const res = await job(() => {
      let i = 0;
      for (i = 0; i < 1000000; i++) {
        // heavy CPU load ...
      }

      return i;
    });

    console.log(res); // 1000000
  } catch (err) {
    console.error(err);
  } finally {
    // shutdown worker pool
    await stop();
  }
})();

Features

  • ๐Ÿ›ข๏ธ Worker Pool
  • ๐Ÿฅ auto self-healing
  • ๐Ÿ™Œ easy and simple
  • ๐Ÿ•” supports both sync and async jobs
  • ๐Ÿ›ก๏ธ huge test coverage
  • ๐Ÿ“œ well documented

Documentation

Dive deep into the documentation to find more examples: Guide

Known Issues

Known Limitations

microjob's People

Contributors

wilk avatar larshp avatar amilajack avatar randy5235 avatar tomjw64 avatar silversonicaxel avatar yovanoc avatar deepsourcebot avatar haidy777 avatar darky avatar pungggi avatar

Stargazers

Nitheesh Murali avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.