microjob

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

Github星跟蹤圖

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

主要指標

概覽
名稱與所有者wilk/microjob
主編程語言TypeScript
編程語言TypeScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2018-08-26 09:31:59
推送於2023-01-04 13:11:29
最后一次提交2021-01-28 08:52:16
發布數21
最新版本名稱v0.7.0 (發布於 2019-10-15 12:02:23)
第一版名稱v0.0.1 (發布於 2018-09-04 09:02:53)
用户参与
星數2k
關注者數27
派生數46
提交數316
已啟用問題?
問題數49
打開的問題數9
拉請求數11
打開的拉請求數13
關閉的拉請求數7
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?