Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

wilk/microjob

Repository files navigation

npm versionBuild StatusCoverage StatusDependencies

A tiny wrapper for turningNode.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 thedefault API.

From version v0.1.0 microjob uses aWorker 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 withNode.js 12+ without flag. WithNode.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

Vianpm:

$ npm install --save microjob

Quick Example

(async()=>{const{ job, start, stop}=require("microjob");try{// start the worker poolawaitstart();// this function will be executed in another threadconstres=awaitjob(()=>{leti=0;for(i=0;i<1000000;i++){// heavy CPU load ...}returni;});console.log(res);// 1000000}catch(err){console.error(err);}finally{// shutdown worker poolawaitstop();}})();

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp