npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

concurrent-request-pool

v1.0.2

Published

A simple request queue with channels and a limit of parallel connections for both the entire queue and a specific channel.

Downloads

6

Readme

Typescript based pool of concurrent requests

The main reasons for the creation

Limiting the HTTP protocol to the number of simultaneous connections can lead to a situation where some JS code completely clogs the request queue for tens of seconds ahead and does not allow critical requests to squeeze through.This solution allows you to manage the number of simultaneous requests, as well as their sorting.

Usage

Create default queue

const pool: ConcurrentRequestPool =  new ConcurrentRequestPool({
  limit: 10, //global limit on concurrent requests, unlimited if limit equal 0 or unspecified
  type: 'pop' //global default queue type, will used in new tube if type field unspecified, if global type not specified 'pop' will be used
});

Push jobs to default tube

const pool: ConcurrentRequestPool =  new ConcurrentRequestPool();
pool.push({
  action: async () => { /* Your async things */ },
});

Remove jobs from default tube

const pool: ConcurrentRequestPool =  new ConcurrentRequestPool();
const jobID: number = pool.push({ // push will return job id
  action: async () => { /* Your async things */ },
});

pool.remove({
  id: jobID // Job's id to remove from default tube
});

Create queue with tubes

const pool: ConcurrentRequestPool =  new ConcurrentRequestPool();
pool.createTube({
  name: 'my_tube', // Tube's name
  limit: 10, // Tube's local limit of concurrent requests, can't be more than global limit
  type: 'pop' // Tube's type, if type unspecified - global type will used, can be pop or shift
});

Push jobs to custom tube

const pool: ConcurrentRequestPool =  new ConcurrentRequestPool();
pool.createTube({ name: 'my_pop_tube', limit: 10, type: 'pop' });
pool.createTube({ name: 'my_shift_tube', limit: 10, type: 'shift' });
//Job to pop tube
pool.push({
  action: async () => { /* Your async things */ },
  tube: 'my_pop_tube',
});
//Job to shift tube
pool.push({
  action: async () => { /* Your async things */ },
  tube: 'my_shift_tube',
});

Remove jobs from custom tube

const pool: ConcurrentRequestPool =  new ConcurrentRequestPool();
pool.createTube({ name: 'my_pop_tube', limit: 10, type: 'pop' });
pool.createTube({ name: 'my_shift_tube', limit: 10, type: 'shift' });
//Job to pop tube, push will return job id
const popJobID: number = pool.push({
  action: async () => { /* Your async things */ },
  tube: 'pop',
});
//Job to shift tube, push will return job id
const shiftJobID: number = pool.push({
  action: async () => { /* Your async things */ },
  tube: 'shift',
});

pool.remove({
  tube: 'my_pop_tube', // Name of tube to remove jobs 
  id: popJobID // Job's id to remove
});
pool.remove({ tube: 'my_shift_tube', id: shiftJobID });

Stop process tube

const pool: ConcurrentRequestPool =  new ConcurrentRequestPool();
pool.createTube({ name: 'my_pop_tube', limit: 10, type: 'pop' });
pool.createTube({ name: 'my_shift_tube', limit: 10, type: 'shift' });

// Disabled tube will stop processing jobs and will not accept new jobs
pool.disableTube({
  name: 'my_shift_tube' // Tube's name to disable
});

Start process tube

const pool: ConcurrentRequestPool =  new ConcurrentRequestPool();
pool.createTube({ name: 'my_pop_tube', limit: 10, type: 'pop' });
pool.createTube({ name: 'my_shift_tube', limit: 10, type: 'shift' });
pool.disableTube({ name: 'my_shift_tube' });

// Enabled tube will process existed jobs and will accept new ones
pool.enableTube({
  name: 'my_shift_tube' // Tube's name to enable
});

Remove custom tube

const pool: ConcurrentRequestPool =  new ConcurrentRequestPool();
pool.createTube({ name: 'my_pop_tube', limit: 10, type: 'pop' });
pool.createTube({ name: 'my_shift_tube', limit: 10, type: 'shift' });

pool.removeTube({
  name: 'my_pop_tube' // Tube's name to remove
});