GithubHelp home page GithubHelp logo

vow-queue's Introduction

vow-queue

NPM Version Build Status

vow-queue is a module for task queue with weights and priorities

Installation

Module can be installed using npm:

npm install vow-queue

or bower:

bower install vow-queue

Usage

var Queue = require('vow-queue'),
    queue = new Queue({ weightLimit : 10 });
    
queue.enqueue(function() { // simple function
    return 2 * 2;
});

queue.enqueue(function() { // function returns a promise
    // do job
    return promise;
});

queue.enqueue( // task with custom priority and weight
    function() {
        // do job
    },
    {
        priority : 3, // this task will be started before the previous two
        weight   : 5
    });
    
queue.start(); // starts tasks processing

queue.enqueue(function() { }); // and enqueue yet another task

API

Creating queue

new Queue([params])

  • params.weightLimit=100 limit of summary tasks weight which can be processed concurrently

Methods of queue

Promise enqueue(taskFn, [taskParams])

Enqueue given task in queue

  • taskFn task function which can return either a promise or a value
  • taskParams.weight=1 weight of given task
  • taskParams.priority=1 priority of given task

Returns promise which will be resolved when given task is done

void start()

Starts processing of tasks in queue

void stop()

Stops processing of tasks in queue

Boolean isStarted()

Returns whether processing is started

void setParams(params)

Sets queue params

  • params.weightLimit=100 limit of summary tasks weight which can be processed concurrently

Object getStats()

Returns statistics about queue

vow-queue's People

Contributors

dfilatov avatar doochik avatar josegonzalez avatar makishvili avatar marcodejongh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vow-queue's Issues

Use of peerDependencies for vow breaks shrinkwrapping of packages using this lib

$ cat package.json  # Note: csscomb depends on vow-fs (& thus vow-queue)
{
  "name": "foobar",
  "private": true,
  "devDependencies": {
    "csscomb": "^2.0.4"
  }
}
$ npm install
<succeeds>
$ npm ls
foobar@ /Users/chris.rebert/code/foobar
└─┬ [email protected]
  ├── [email protected]
  ├── [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ └── [email protected]
  ├── [email protected]
  └─┬ [email protected]
    ├── [email protected]
    └─┬ [email protected]
      └── UNMET DEPENDENCY vow ~0.3.9

npm ERR! missing: vow@~0.3.9, required by [email protected]
npm ERR! not ok code 0
$ npm shrinkwrap
npm ERR! Error: Problems were encountered
npm ERR! Please correct and try again.
npm ERR! missing: vow@~0.3.9, required by [email protected]
npm ERR!     at shrinkwrap_ (/usr/local/share/npm/lib/node_modules/npm/lib/shrinkwrap.js:30:15)
npm ERR!     at /usr/local/share/npm/lib/node_modules/npm/lib/shrinkwrap.js:24:5
npm ERR!     at /usr/local/share/npm/lib/node_modules/npm/lib/ls.js:44:30
npm ERR!     at /usr/local/share/npm/lib/node_modules/npm/node_modules/read-installed/read-installed.js:130:5
npm ERR!     at /usr/local/share/npm/lib/node_modules/npm/node_modules/read-installed/read-installed.js:258:14
npm ERR!     at cb (/usr/local/share/npm/lib/node_modules/npm/node_modules/slide/lib/async-map.js:48:11)
npm ERR!     at /usr/local/share/npm/lib/node_modules/npm/node_modules/read-installed/read-installed.js:258:14
npm ERR!     at cb (/usr/local/share/npm/lib/node_modules/npm/node_modules/slide/lib/async-map.js:48:11)
npm ERR!     at /usr/local/share/npm/lib/node_modules/npm/node_modules/read-installed/read-installed.js:258:14
npm ERR!     at cb (/usr/local/share/npm/lib/node_modules/npm/node_modules/slide/lib/async-map.js:48:11)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Darwin 13.1.0
npm ERR! command "node" "/usr/local/bin/npm" "shrinkwrap"
npm ERR! cwd /Users/chris.rebert/code/foobar
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.9
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/chris.rebert/code/foobar/npm-debug.log
npm ERR! not ok code 0

Test fails

Clone repository
run "npm install"
run "npm test"

`

[email protected] test /Users/dmk/Work/vow-queue
make validate

./node_modules/.bin/jshint .
./node_modules/.bin/jscs .
/Users/dmk/Work/vow-queue/node_modules/vow-fs/lib/fs.js:152
var promise = Vow.promise();
^

TypeError: Vow.promise is not a function
at Object.exists (/Users/dmk/Work/vow-queue/node_modules/vow-fs/lib/fs.js:152:31)
at Object.checkPath (/Users/dmk/Work/vow-queue/node_modules/jscs/lib/checker.js:204:22)
at /Users/dmk/Work/vow-queue/node_modules/jscs/lib/cli.js:39:28
at Array.map (native)
at Object. (/Users/dmk/Work/vow-queue/node_modules/jscs/lib/cli.js:38:30)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
make: *** [lint] Error 1
npm ERR! Test failed. See above for more details.
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.