Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wilk/microjob
A tiny wrapper for turning Node.js worker threads into easy-to-use routines for heavy CPU loads.
https://github.com/wilk/microjob
jobs multithreading nodejs thread threading
Last synced: 5 days ago
JSON representation
A tiny wrapper for turning Node.js worker threads into easy-to-use routines for heavy CPU loads.
- Host: GitHub
- URL: https://github.com/wilk/microjob
- Owner: wilk
- License: mit
- Created: 2018-08-26T09:31:59.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T13:11:29.000Z (about 2 years ago)
- Last Synced: 2025-01-09T18:27:46.066Z (12 days ago)
- Topics: jobs, multithreading, nodejs, thread, threading
- Language: TypeScript
- Homepage: https://wilk.github.io/microjob/
- Size: 1.95 MB
- Stars: 2,026
- Watchers: 28
- Forks: 47
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - microjob - to-use routines for heavy CPU loads. | wilk | 1969 | (TypeScript)
README
# Microjob
[![npm version](https://badge.fury.io/js/microjob.svg)](https://badge.fury.io/js/microjob)
[![Build Status](https://travis-ci.org/wilk/microjob.svg?branch=master)](https://travis-ci.org/wilk/microjob)
[![Coverage Status](https://coveralls.io/repos/github/wilk/microjob/badge.svg?branch=feature%2Fcoverage)](https://coveralls.io/github/wilk/microjob?branch=feature%2Fcoverage)
[![Dependencies](https://img.shields.io/david/wilk/microjob.svg)](https://david-dm.org/wilk/microjob?path=packages/microjob)A tiny wrapper for turning [Node.js threads](https://nodejs.org/api/worker_threads.html) 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](https://nodejs.org/api/worker_threads.html).~~
From version v0.1.0 microjob uses a **[Worker Pool](GUIDE.md#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](https://medium.com/hackernoon/microjob-a-tiny-multithreading-library-for-node-js-92d0500b07d5)**
## Installation
Via **npm**:
```bash
$ npm install --save microjob
```## Quick Example
```js
(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](GUIDE.md)**
## Known Issues
- **[sanitize worker context](GUIDE.md#job-context)**
## Known Limitations
- **[serialize worker data](GUIDE.md#job-data)**
- **[passing runtime context](GUIDE.md#job-context)**