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

narrow

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

narrow

Library shrinks a given callback parallel execution concurrency in a limited number of threads, receiving the bunch of data (array of tasks).

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Introduction

node-narrow is a library which shrinks a given callback parallel execution in a limited number of threads, receiving the bunch of data (array of tasks).

Inspired from node-async#queue.

Synopsis

Push a big bunch of data and handle it in maximum 5 simultaneous threads:

var Narrow = require('narrow');

var narrow = new Narrow(5, function(str, callback){
    setTimeout(function(){
        callback(null, str.toUpperCase());
    }, 1000)
})

var tasks = [];
for (var i = 0; i < 10; i++) {
    tasks.push('something' + i);
}

var start = new Date;

narrow.on('complete', function(result){
    console.log('%s after %dms', result, new Date - start);
});

narrow.pushAll(tasks, function(){
    console.log('done');
})

Will output:

SOMETHING0 after 1002ms
SOMETHING1 after 1012ms
SOMETHING2 after 1012ms
SOMETHING3 after 1012ms
SOMETHING4 after 1012ms
SOMETHING5 after 2012ms
SOMETHING6 after 2012ms
SOMETHING7 after 2013ms
SOMETHING8 after 2016ms
SOMETHING9 after 2016ms
done

Timeouts support

todo: document

See more examples in examples directory.

Installation

npm install narrow

FAQs

Package last updated on 11 Aug 2011

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