Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

microjob

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microjob - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

6

package.json
{
"name": "microjob",
"version": "0.3.0",
"version": "0.3.1",
"description": "A tiny wrapper for Node.js worker_threads lib",

@@ -19,3 +19,4 @@ "main": "dist/job.js",

"prerelease": "npm run lint; npm test; npm run build; npm run docs",
"report-coverage": "node --experimental-worker node_modules/.bin/jest --coverage && cat ./coverage/lcov.info | coveralls"
"report-coverage": "node --experimental-worker node_modules/.bin/jest --coverage && cat ./coverage/lcov.info | coveralls",
"rel": "gren release"
},

@@ -76,2 +77,3 @@ "engines": {

"gitbook-cli": "^2.3.2",
"github-release-notes": "^0.17.0",
"jest": "^23.6.0",

@@ -78,0 +80,0 @@ "ts-jest": "^23.10.0",

# Microjob
[![npm version](https://badge.fury.io/js/microjob.svg)](https://badge.fury.io/js/microjob)

@@ -14,5 +15,9 @@ [![Build Status](https://travis-ci.org/wilk/microjob.svg?branch=master)](https://travis-ci.org/wilk/microjob)

## 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).
~~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.

@@ -28,2 +33,3 @@ Quoting the documentation:

## Installation
Via **npm**:

@@ -36,13 +42,14 @@

## Quick Example
```js
(async () => {
const { job, start, stop } = require('microjob')
const { job, start, stop } = require("microjob");
try {
// start the worker pool
await start()
await start();
// this function will be executed in another thread
const res = await job(() => {
let i = 0
let i = 0;
for (i = 0; i < 1000000; i++) {

@@ -52,22 +59,26 @@ // heavy CPU load ...

return i
})
return i;
});
console.log(res) // 1000000
console.log(res); // 1000000
} catch (err) {
console.error(err)
console.error(err);
} finally {
// shutdown worker pool
stop()
await stop();
}
})()
})();
```
## Documentation
Dive deep into the documentation to find more examples: **[Guide](GUIDE.md)**
## Known Issues
* **[sanitize worker context](API.md#job-context)**
- **[sanitize worker context](GUIDE.md#job-context)**
## Known Limitations
* **[serialize worker data](API.md#job-data)**
- **[serialize worker data](GUIDE.md#job-data)**
- **[passing runtime context](GUIDE.md#job-context)**
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc