Socket
Socket
Sign inDemoInstall

hals

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hals

A concurrency limiter that has a maximum capacity for queued-up functions


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
5.49 kB
Created
Weekly downloads
 

Readme

Source

hals

Build Status

hals (is German for throat) is a concurrency limiter that has a maximum capacity for queued-up functions. When the capacity is reached newly added tasks will be dropped. New tasks will be accepted once it has capacity again.

Unlike a queue, hals does not have a worker function that takes queued payloads but instead takes functions and executes them.

The analogy goes as follows:

  • Only concurrency things can go down the throat at the same time.
  • But the mouth and throat can only hold capacity things. Everything else drops on the floor.

Install

npm install hals --save

Usage

var hals = require('hals');

function drain () {
  console.log('drained');
}

function drop (usedCapacity, fn) {
  console.log('dropped', fn.name, 'used capacity:', usedCapacity);
}

var feed = hals({
  capacity: 3,    // optional; default: null (null = unlimited capacity)
  concurrency: 1, // optional; default: 1
  drain: drain,   // optional; default null; function to be called when queue is empty
  drop: drop      // optional; default null; function to be called when a function is dropped. Receives task as first argument
});

var foods = [  
  'broccoli',
  'tomato',
  'beans',
  'pork'
];

// add some tasks to hals
foods.forEach(function (food) {
  feed(function (next) {
    console.log('ate', food);
    next();
  });
});

// after a while add another task
setTimeout(function () {
	feed(function (next) {
	  console.log('ate zucchini');
	  next();
	});
}, 100);

prints:

dropped task used capacity: 3
ate broccoli
ate tomato
ate beans
drained

// didn't eat pork

ate zucchini
drained

License

MIT

Keywords

FAQs

Last updated on 10 Jun 2015

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