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

fanin

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fanin

fanin - the fan-in concurrency pattern

1.0.5
latest
Source
npm
Version published
Weekly downloads
5
150%
Maintainers
1
Weekly downloads
 
Created
Source

node-fanin Build Status

A simple concurrency pattern: fan-in

Status: Untested in production, but ready to be.

Why do you need fan-in?

  • You want to make n asynchronous calls simultaneously and make a callback when all have finished.
  • You may want to save the callback values of these calls, and definitely want the errors.
  • You just want that. Nothing else.

API

Usage:

var fanin = require('fanin')
  , fan = fanin(number_of_callbacks, final_callback);

asyncCall(fan); // repeat...
asyncCall(fan.capture('field'));
asyncCall(fan.ordered(index));
...
fan.timeout(err)


// final_callback( error_array, return_value_object );

Basic Usage (no return values, just an unorded list of errors):

var fan = fanin(2, cb);

foo(fan);
bar(fan);

function foo(cb) { cb(new Error('some error')); }

function bar(cb) { cb(null); }

// cb([ Error('some error') ]);

Storing return value(s):

var fan = fanin(2, cb);

foo(fan.capture('foo'));
bar(fan.capture('bar'));

function foo(cb) { cb(null, 'foobaz'); }

function bar(cb) { cb(null, 'bar', 'baz'); }

// cb(undefined, { foo: 'foobaz', bar: [ 'bar', 'baz' ] } );

Storing return values in an ordered array:

var fan = fanin(2, cb);

foo(fan.ordered(1));
bar(fan.ordered(0));

function foo(cb) { cb(null, 'foobaz'); }

function bar(cb) { cb(null, 'barbaz'); }

// cb(undefined, { ordered: [ 'barbaz', 'foobaz' ] } );

Timeouts on these calls:

var fan = fanin(2, cb);

fan.timeout(new Error('timeout!'));

// cb([ Error('timeout!') ])

Installation

npm install fanin

Tests

npm test

License

MIT License found in the LICENSE file.

Keywords

flowcontrol

FAQs

Package last updated on 26 Feb 2013

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