# Better Queue - Powerful flow control [![npm package](https://nodei.co/npm/better-queue.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/better-queue/) [![Build status](https://img.shields.io/travis/diamondio/better-queue.svg?style=flat-square)](https://travis-ci.org/diamondio/better-queue) [![Dependency Status](https://img.shields.io/david/diamondio/better-queue.svg?style=flat-square)](https://david-dm.org/diamondio/better-queue) [![Known Vulnerabilities](https://snyk.io/test/npm/better-queue/badge.svg?style=flat-square)](https://snyk.io/test/npm/better-queue) [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square)](https://gitter.im/diamondio/better-queue?utm_source=badge) ## Super simple to use Better Queue is designed to be simple to set up but still let you do complex things. - Persistent (and extendable) storage - Batched processing - Prioritize tasks - Merge/filter tasks - Progress events (with ETA!) - Fine-tuned timing controls - Retry on fail - Concurrent batch processing - Task statistics (average completion time, failure rate and peak queue size) - ... and more! --- #### Install (via npm) ```bash npm install --save better-queue ``` --- #### Quick Example ```js var Queue = require('better-queue'); var q = new Queue(function (input, cb) { // Some processing here ... cb(null, result); }) q.push(1) q.push({ x: 1 }) ``` ## Table of contents - [Queuing](#queuing) - [Task Management](#task-management) - [Queue Management](#queue-management) - [Advanced](#advanced) - [Storage](#storage) - [Full Documentation](#full-documentation) --- You will be able to combine any (and all) of these options for your queue! ## Queuing It's very easy to push tasks into the queue. ```js var q = new Queue(fn); q.push(1); q.push({ x: 1, y: 2 }); q.push("hello"); ``` You can also include a callback as a second parameter to the push function, which would be called when that task is done. For example: ```js var q = new Queue(fn); q.push(1, function (err, result) { // Results from the task! }); ``` You can also listen to events on the results of the `push` call. ```js var q = new Queue(fn); q.push(1) .on('finish', function (result) { // Task succeeded with {result}! }) .on('failed', function (err) { // Task failed! }) ``` Alternatively, you can subscribe to the queue's events. ```js var q = new Queue(fn); q.on('task_finish', function (taskId, result, stats) { // taskId = 1, result: 3, stats = { elapsed: