• Stars
    star
    2,016
  • Rank 22,960 (Top 0.5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

ng-websocket

AngularJS HTML5 WebSocket powerful library
JavaScript
269
star
2

ExtJS-WebSocket

Ext.ux.WebSocket is an extension to manage HTML5 WebSocket with ExtJS and SenchaTouch
JavaScript
119
star
3

node-certification

Strongloop Node.js Certification Exam work out
JavaScript
59
star
4

Ext.ux.Deferred

Promises for ExtJS 4 and Sencha Touch
JavaScript
52
star
5

Ext.ux.data.proxy.WebSocket

An easy-to-use implementation of the ExtJS/Sencha Touch proxy, using HTML5 WebSocket.
JavaScript
46
star
6

thanc

⭐ Thanc: a smarty way to thank NPM packages authors by starring their repos
JavaScript
38
star
7

ExtJS-WebWorker

Ext.ux.WebWorker is an extension to manage HTML5 WebWorker with ExtJS and Sencha Touch
JavaScript
22
star
8

Ext.ux.Ajax

A revisited implementation with Ext.ux.Deferred of the well known Ext.Ajax singleton.
JavaScript
12
star
9

shary

Share your files effortlessly with QRCodes
JavaScript
11
star
10

Ext.ux.EventSource

Wrapper for EventSource HTML5 object to manage SSE (Server Sent Event) with ExtJS and Sencha Touch.
JavaScript
9
star
11

snpm

Secure NPM PoC
JavaScript
9
star
12

SPAM

Social Production of Audiovisual Microblogs
PHP
7
star
13

Ext.ux.GMapManager

ExtJS Manager to handle many Google Maps in a single container.
JavaScript
4
star
14

AngularJS-Amsterdam-Conference

Slideshow built with RevealJS for the AngularJS Amsterdam Conference
JavaScript
4
star
15

backend-api-go

A simple RESTful API (CRUD) built with GoLang
Go
3
star
16

zend-php-certification

Zend PHP Certification
PHP
3
star
17

from-csv-to-buxfer

Pushing CSV data to Buxfer with Buxfer APIs
Go
3
star
18

docker-advanced-nodejs

Node.js app sources for the Docker Advanced Workshop
JavaScript
3
star
19

push-notifications-ionic2

An example of Push Notifications with Ionic 2
TypeScript
2
star
20

TEWC

The Easiest Web Chat
JavaScript
2
star
21

TEWC-Node

The Easiest Web Chat with NodeJS :: real-time multi-user multi-room web chat
JavaScript
2
star
22

introducing-golang

Introducing GoLang slideshow
JavaScript
2
star
23

outlier-coding-challenge

Outlier coding challenge
TypeScript
2
star
24

go-test

My personal tests with go lang
Go
2
star
25

crud-example-node

A CRUD RESTful APIs built with Node.js
JavaScript
2
star
26

screeba-console

Console transport for Screeba
JavaScript
1
star
27

FOAF-Card

Simple example of how can you use 'foaf.rdf' personal representation.
JavaScript
1
star
28

express-middleware-sse

Middleware to handle Server Sent Events with love
1
star
29

GulpVSGrunt

My personal experiments on GulpJS and GruntJS
JavaScript
1
star
30

golang-http2

HTTP/2 test with GoLang
HTML
1
star
31

ng-websocket-directive

AngularJS HTML5 WebSocket powerful directive
JavaScript
1
star
32

Geckoboard-Github

Geckoboard coding challenge
JavaScript
1
star
33

wilk

HTML
1
star
34

awesome-rants

An agnostic collection of your best rants against frameworks, languages and in general techs
1
star
35

dpc18bot

Dutch PHP Conference 2018 Telegram Bot
Elixir
1
star
36

VOWLAN

VoIP Over Wireless LAN
C
1
star
37

SVD88

Sistema di Elaborazione di Segnali Video Digitali
Assembly
1
star
38

IAS

Italian Air Strike Game
Java
1
star
39

TrackList

Creating songs list
Python
1
star
40

CoffeeScript-Presentation

Slides for a CoffeeScript presentation, built with reveal.js
CSS
1
star
41

ext5-test

Personal test on ExtJS 5
JavaScript
1
star
42

Kaya-2010

Micro Kernel for uMPS
C
1
star
43

winston-waterline

Winston transporter for Waterline
JavaScript
1
star
44

table-to-heatmap

Convert a table (CSV) to a heatmap (D3)
HTML
1
star
45

sencha-certification

JavaScript
1
star
46

nixa-coding-challenge

JavaScript
1
star
47

a-better-company-culture

A Better Company Culture Manifesto
1
star
48

angular2-backend

A backend for an app built with Angular 2
JavaScript
1
star
49

screeba-file

File transport for Screeba
JavaScript
1
star