New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

at-a-time

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

at-a-time

at-a-time

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

at-a-time

at-a-time allows you to do do asynchronous operations simultaneously but with a max number of operations going at any one time.

Why?

Promise.all() allows you to simultaneously do asynchronous operations and a for loop in an async function allows you to sequentially do asynchronous operations. But, sometimes you have more operations than you can handle at once and it would take too long to handle them sequentially. at-a-time allows you to do do asynchronous operations simultaneously but with a max number of operations going at any one time.

Installation

$ npm install at-a-time

Usage

// import library
const atATime = require('at-a-time');

const endpoints = [
  'https://api.something.com/12345',
  'https://api.something.com/23451',
  'https://api.something.com/34512',
  'https://api.something.com/45123',
  'https://api.something.com/51234',
  'https://api.something.com/23456',
  'https://api.something.com/62345',
  'https://api.something.com/56234',
  'https://api.something.com/45623',
  'https://api.something.com/34562'
];

// create an array of Promise-returning functions
const operations = endpoints
  .map(e => () => request.get(e));

// Work through the operations keeping two
// simultaneous operations going at a time.

// Usage with manual Promise handling
atATime(2, operations)
  .then(res => {
    console.log(res); // array of responses in order
  })
  .catch(err => {
    // handle error
  });

// Usage within an sync function
async function() {
  try {
    const res = await atATime(2, operations);
    console.log(res); // array of responses in order
  } catch(err) {
    // handle error
  }
};

// Usage within a generator function
co(function*() {
  try {
    const res = yield atATime(2, operations);
    console.log(res); // array of responses in order
  } catch(err) {
    // handle error
  }
});

Running Tests

$ npm install
$ npm test

License

Apache License Version 2.0

Keywords

FAQs

Package last updated on 28 Nov 2018

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