A simple request queue with channels and a limit of parallel connections for both the entire queue and a specific channel.
npm install concurrent-request-pooltypescript
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
});
`
$3
`typescript
const pool: ConcurrentRequestPool = new ConcurrentRequestPool();
pool.push({
action: async () => { / Your async things / },
});
`
$3
`typescript
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
});
`
$3
`typescript
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
});
`
$3
`typescript
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',
});
`
$3
`typescript
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 });
`
$3
`typescript
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
});
`
$3
`typescript
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
});
`
$3
`typescript
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
});
``