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

callback-queue

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

callback-queue

Put your callbacks into queue to make sure that concurrent requests that you might want to perform will only be executed once

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
545
increased by163.29%
Maintainers
1
Weekly downloads
 
Created
Source

Callback queue

Codacy Badge

Node.js callback queue. Can be used with browserify as well.

Idea is to queue callbacks, when same function wants to be called at the same time by different callers.

One example would be conserving resources spent on outgoing http requests.

npm install callback-queue -S

Example usage

  1. callbackQueue.add(String, Function): queues callbacks based on key attribute
  2. callbackQueue.remove(String, Error): calls queued callbacks with Error argument
const callbackQueue = require('callback-queue');
const request = require('request');

function performOutgoingRequest(url, next) {
  const callback = callbackQueue.add(url, next);
  if (!callback) {
    return;
  }

  request(url, callback);
}

for (let i = 0; i < 100; i++) {
  // request itself will be performed just once
  performOutgoingRequest('https://google.com', function niceCallback(err, resp, body) {
    // will be called 100 times
  });
}

for (let x = 0; x < 100; x++) {
  // request itself will be performed just once
  performOutgoingRequest('https://google.com', function niceCallback(err, resp, body) {
      // will be called 100 times with Error object
  });
}

callbackQueue.remove('https://google.com', new Error('cancel it!'));

Keywords

FAQs

Package last updated on 12 Sep 2019

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