New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

timequeue

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timequeue

A queue with custom concurrency and time limits.

Source
npmnpm
Version
0.1.2
Version published
Weekly downloads
50
-61.83%
Maintainers
1
Weekly downloads
 
Created
Source

timequeue.js Build Status

A queue with custom concurrency and time limits. Inspired by caolan/async#queue, but with variable number of arguments in the worker, events, and with optional time limits.

Usage

var TimeQueue = require('timequeue');

function worker(arg1, arg2, callback) {
  someAsyncFunction(calculation(arg1, arg2), callback);
}

// create a queue with max 5 concurrency every second
var q = new TimeQueue(worker, 5, 1000);

// push tasks onto the queue
q.push(42, 24);
q.push(2, 74);

// optional callback when pushing tasks
q.push(2, 2, function(err) {
  // task finished
});

API

new TimeQueue(worker, [concurrency], [time])

Creates a new instance of a queue. Worker must be a function with a callback for its last argument. The callback must be called in order for the queue to know when the worker has finished a task. concurrency defaults to 1 and time to 1000. Meaning one task in the queue will be executed a maximum of one time per second. If time is set to 0, there will be no time limit.

worker, concurrency and time properties can later be edited on the queue instance.

TimeQueue#active

How many tasks are currently active.

TimeQueue#queued

How many tasks are currently in the queue.

TimeQueue#push(data..., [callback])

Pushes a new task to the queue. Any number of arguments can be given. An optional callback can also be given as the last parameter. The callback will be called when the task is finished or if there was any error.

TimeQueue#die()

Empties queue and clears the timeouts TimeQueue sets to keep track of running tasks. Currently running tasks will still complete.

Events

Event: 'error'

  • Error

Emitted when there is an error processing a task and a callback isn't given to the push method.

Event: 'full'

Queue is full.

Event: 'empty'

Queue is empty, some tasks might still be running.

Event: 'drain'

Queue is empty and last task has finished.

Install

npm install timequeue

Tests

Tests are written with mocha

npm test

License

MIT

Keywords

queue

FAQs

Package last updated on 19 Aug 2012

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