Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

queue-async

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

queue-async

A little helper for asynchronous JavaScript.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9K
decreased by-16.34%
Maintainers
1
Weekly downloads
 
Created
Source

queue.js

Queue.js is yet another asynchronous helper library for JavaScript. Think of it as a minimalist version of Async.js that allows fine-tuning over parallelism. Or, think of it as a version of TameJs that does not use code generation.

For example, if you wanted to stat two files in parallel:

queue()
    .defer(fs.stat, __dirname + "/../Makefile")
    .defer(fs.stat, __dirname + "/../package.json")
    .await(function(error, file1, file2) { console.log(file1, file2); });

Or, if you wanted to run a bazillion asynchronous tasks (here represented as an array of closures) serially:

var q = queue(1);
tasks.forEach(function(t) { q.defer(t); });
q.awaitAll(function(error, results) { console.log("all done!"); });

Queue.js can be run inside Node.js or in a browser.

API Reference

queue([parallelism])

Constructs a new queue with the specified parallelism. If parallelism is not specified, the queue has infinite parallelism. Otherwise, parallelism is a positive integer. For example, if parallelism is 1, then all tasks will be run in series. If parallelism is 3, then at most three tasks will be allowed to proceed concurrently; this is useful, for example, when loading resources in a web browser.

queue.defer(method[, arguments…])

Adds the specified method to the queue, with any optional arguments. The method is called with the optional arguments and a final callback argument, which should be called when the task has finished.

queue.await(callback)

queue.awaitAll(callback)

Sets the callback to be notified when all deferred tasks have finished. If await is used, each result is passed as a separate argument; if awaitAll is used, the entire array of results is passed as a single argument.

Callbacks

The callbacks follow the Node.js convention where the first argument is an optional error object, and the second is used to pass on the result of an operation. Queue.js does not directly support asynchronous functions that return multiple results; however, you can homogenize such functions by wrapping them and converting multiple results into a single object or array.

Keywords

FAQs

Package last updated on 25 Jan 2013

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc