Socket
Book a DemoInstallSign in
Socket

queuealot

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

queuealot

Bike shed queing module using closures for augmenting each result

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

queuealot

Bike shed queing module using closures for augmenting each result. All jobs are run in series one at a time.

There are many, many other queueing modules out there, so why queuealot? Queuealot gives you the freedom to work with and augment each result from each job on the queue as they come in (see more below).

Build status js-standard-style

Installation

npm install queuealot

Usage

var queuealot = require('queuealot')

// initialize a new queue
var queue = queuealot(function (err, results) {
  if (err) throw err
  console.log(results) // => ['foo']
})

// add a job to the queue
queue(function (callback) {
  // do your stuff here and call the callback when done with an optional
  // error and the result
  callback(null, 'foo')
})

Gotcha: Add all the jobs to the queue before the next tick. The queue expects that all jobs are added to the queue within the same tick as the queue was initialized. On the next tick the queue will run, execute all jobs on the queue and call the final function given when initialized.

Why?

Ok the above example isn't really that useful. Let's instead say you are reading a bunch of files and want to know the filename that generated each result:

var queuealot = require('queuealot')
var fs = require('fs')

var queue = queuealot(function (err, files) {
  if (err) throw err
  files.forEach(function (file) {
    console.log(file.path)
    console.log(file.body)
  })
})

queue(function (callback) {
  var path = '/path/to/file.txt'
  fs.readFile(path, function (err, data) {
    if (err) return callback(err)
    callback(null, { path: path, body: data })
  })
})

queue(function (callback) {
  var path = '/path/to/other/file.txt'
  fs.readFile(path, function (err, data) {
    if (err) return callback(err)
    callback(null, { path: path, body: data })
  })
})

License

MIT

Keywords

queue

FAQs

Package last updated on 22 Jun 2015

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