🚀 DAY 3 OF LAUNCH WEEK: Introducing Webhook Events for Pull Request Scans.Learn more →
Socket
Book a DemoInstallSign in
Socket

housecall

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

housecall

A promise queue. Simple and sweet.

latest
Source
npmnpm
Version
1.4.1
Version published
Maintainers
1
Created
Source

Push promise-returning functions to the queue. Set the concurrency, and optionally a cooldown.

The queue is best understood as an airport runway: each function takes off with a minimum distance of the cooldown in milliseconds. Concurrency is the number of flights that can currently be in the air. When promises resolve, the plane has landed.

Install

npm install housecall

Usage

var housecall = require('housecall');
var axios = require('axios');

var queue = housecall({ concurrency: 2, cooldown: 1000 });

queue.push(() => axios.get('https://twitter.com/').then((response, body) => {
	// The eventual response of Twitter	
}));

// This request will not start until 1000 ms after the above.
queue.push(() => axios.get('https://some.com/').then((response, body) => {
	// ...
}));

// This will not run until of the above have terminated.
queue.push(() => axios.get('https://test.com/').then((response, body) => {
	// ...
}));

Make sure you wrap the function. Otherwise it will run immediately, and defeat the purpose of the queue.

// WILL NOT BE CORRECTLY ENQUEUED
queue.push(axios.get('https://twitter.com/').then((response, body) => {
	// The queue will not control the start of execution here.
}));

Events

Whenever the queue is empty after handling tasks, it will emit an 'idle' event.

queue.on('idle', function(noTasksCompleted, noTasksWithError) {
	// Do something
});

Errors

The queue continues on any error, but the error will be outputted to stdout.

Keywords

promise

FAQs

Package last updated on 25 Nov 2016

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