New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bobbin

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bobbin

easily spool up thread-like worker processes

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-90.62%
Maintainers
1
Weekly downloads
 
Created
Source

bobbin

easily spool up thread-like worker processes in node with bobbin

NPM

// to create a pool of workers:

var bobbin = require('bobbin');

// create 4 processes; defaults to os.cpus().length
bobbin.create(4, function(err, pool) {

	// to send some work (in this case concatenate two strings `left' and `right'):

	var left = 'foo', right = 'bar';
	pool.run(
		left, right, // you have to explicitly pass variables
		function remoteWorkFunction(left, right, callback) {
	    	callback(left + right);
	    },
	    function localCallback(result) {
	    	assert(result === 'foobar');
	    }
	);

});

for clarity, the signature of pool.run is:

pool.run(varsToSend..., workFunction, localCallback)

stuff to keep in mind:

  1. calls to pool.run() are dispatched to workers in a round-robin fashion, though idle workers are prioritized.
  2. you can't send closures to workers, so explicitly send data in the first arguments to pool.run(). those arguments will be passed verbatim into your work function.
  3. your local callback gets called with whatever your work function calls back with.
  4. to create() a pool, you have to be the cluster master, i.e. cluster.isMaster

Apache License 2.0, see LICENSE for info.

Keywords

FAQs

Package last updated on 01 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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