Socket
Socket
Sign inDemoInstall

mini-queue

Package Overview
Dependencies
2
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mini-queue

Job queue


Version published
Maintainers
1
Install size
79.8 kB
Created

Readme

Source

npm version Build Status Coverage Status Code Climate Inch CI

Dependency Status devDependency Status

mini-queue

Job queue

If you have different needs regarding the functionality, please add a feature request.

Installation

npm install --save mini-queue

Usage

 QueueJob State Diagram (methods of JobQueue object)
 ======================

             |
   createJob |
      +------V-----+
      | new        |
      |            |
      +---+--+--+--+
          |  |  | _rejectJob                     +------------+
          |  |  +--------------------------------> reject     |
          |  |                                   |            |
_startJob |  | _queueJob                         +------------+
          |  +------------+
          |               |
          |         +-----v------+ _cancelJob
          |         | queue      +-----------------+
          |         |            |                 |
          |         +---+----^---+                 |
          | _dequeueJob |    |                     |
          |             |    |                     |
          |             |    | _queueJob           |
          |         +---v----+---+   _cancelJob  +-V----------+
          |         | dequeue    +---------------> cancel     |
          |         |            |               |            |
          |         +-----+------+               +------------+
          |               | _startJob
          |               |
          |    +----------+
          |    |
      +---v----v---+  _terminateJob       +------------+
      | process    +----------------------> terminate  |
      |            |                      |(not implem)|
      +-----+------+                      +------------+
            |
            |
            |
      +-----v------+
      | complete   |
      |            |
      +------------+

Example

You may find this example in demo subdirectory of the package.

"use strict";

process.env.DEBUG = 'queue,app';// + (process.env.DEBUG || '');
var debug   = require('debug')('app');


var Queue = require('express-queue');
//var Queue = require('../');
var queue = new Queue({ activeLimit: 1, queuedLimit: 1 });

// create jobs
var maxCount = 5,
    count = 0;

var interval = setInterval(function() {        
  var jobData = {};
  // Create new job for the queue
  // If number of active job is less than `activeLimit`, the job will be started on Node's next tick.
  // Otherwise it will be queued.
  queue.createJob(jobData); // we may pass some data to job when calling queue.createJob() function
  if (++count >= maxCount) {
    clearInterval(interval);
  }
}, 500);


// execute jobs

queue.on('process', function(job, jobDone) {
  debug('queue.on(\'process\'): ['+job.id+']');
  // Here the job starts
  // Imitate job processing which takes 1 second to be finished
  // job.data is set to value passed to queue.createJob()
  setTimeout(function() {
    // Call the callback to signal to the queue that the job has finished
    // and the next one may be started
    jobDone();
    // Now on Node's next tick the next job (if any) will be started
  }, 1000);
});

// Signal about jobs rejected due to queueLimit

queue.on('reject', function(job) {
  debug('queue.on(\'reject\'): ['+job.id+']');
});

Credits

Alexander

github.com   npmjs.com   travis-ci.org   coveralls.io   inch-ci.org

License

MIT

Keywords

FAQs

Last updated on 14 Jun 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc