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

throng

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

throng - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

15

lib/throng.js

@@ -14,7 +14,15 @@ 'use strict';

const NOOP = () => {};
module.exports = function throng(options, startFunction) {
let startFn = typeof options === 'function' ?
options : startFunction;
options = options || {};
let startFn = options.start || startFunction || options;
let masterFn = options.master || NOOP;
if (cluster.isWorker) return startFn(cluster.worker.id);
if (typeof startFn !== 'function') {
throw new Error('Start function required');
}
if (cluster.isWorker) {
return startFn(cluster.worker.id);
}

@@ -28,2 +36,3 @@ let opts = isNaN(options) ?

listen();
masterFn();
fork();

@@ -30,0 +39,0 @@

2

package.json
{
"name": "throng",
"version": "3.0.0",
"version": "4.0.0",
"description": "A simple worker-manager for clustered apps",

@@ -5,0 +5,0 @@ "keywords": [

@@ -34,2 +34,4 @@ # Throng

Simplest; automatically fork 1 worker per CPU core:
```js

@@ -39,3 +41,3 @@ throng(startFunction);

Provide a worker count:
Specify a number of workers:

@@ -49,3 +51,8 @@ ```js

```js
throng({ workers: 16, grace: 1000 }, startFunction);
throng({
workers: 16,
grace: 1000,
master: masterFunction,
start: startFunction
});
```

@@ -77,2 +84,50 @@

## A Complex example
```js
const throng = require('./lib/throng');
throng({
workers: 4,
master: startMaster,
start: startWorker
});
// This will only be called once
function startMaster() {
console.log(`Started master`);
}
// This will be called four times
function startWorker(id) {
console.log(`Started worker ${ id }`);
process.on('SIGTERM', () => {
console.log(`Worker ${ id } exiting...`);
console.log('(cleanup would happen here)');
process.exit();
});
}
```
```
$ node example-complex.js
Started master
Started worker 1
Started worker 2
Started worker 3
Started worker 4
$ killall node
Worker 3 exiting...
Worker 4 exiting...
(cleanup would happen here)
(cleanup would happen here)
Worker 2 exiting...
(cleanup would happen here)
Worker 1 exiting...
(cleanup would happen here)
```
## Tests

@@ -79,0 +134,0 @@

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