Socket
Socket
Sign inDemoInstall

fanin

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fanin

fanin - the fan-in concurrency pattern


Version published
Weekly downloads
10
increased by42.86%
Maintainers
1
Install size
7.84 kB
Created
Weekly downloads
 

Readme

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

FAQs

Last updated on 26 Feb 2013

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc