rygr.async-queue
Async queue mechanism
Last updated 5 years ago by camachgk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rygr.async-queue 
SYNC missed versions from official npm registry.

Async Queue

asyncQueue = require 'rygr.async-queue'

Async queue allows you to assemble a series of asynchronous methods to be run in a sequence. This is inspired by Express' middleware feature.

Require

asyncQueue = require 'rygr.async-queue'

or, in JavaScript

asyncQueue = require('rygr.async-queue')

Dependencies

  • For the browser build, async queue depends on jQuery
  • For the node build, async queue depends on q

These dependency differences are denoted in the bower.json and package.json files.

Arguments

Async queue takes three arguments:

  • Args Array|null (required) An array of arguments to be passed to each method in the queue
  • Queue Array<Functions>* (required) An array of functions to be called in sequence. Each function will receive the arguments passed in and an extra next function to trigger the next function in the queue (required). An error function can be included and is expected to take an extra argument.
  • Done Function (optional) A callback function to be executed when the sequence completes or is short-circuited because of an error. It will receive an error as it's first argument if one occured, or null otherwise.

Useage

asyncQueue = require 'rygr.async-queue'

first = (name, next) ->
  console.log "#{ name }: first!"
  next()

# Throwing an error (or calling next with an error) will cause the queue to skip
# to the error function or skip to call done if none is provided
second = (name, next) ->
  throw new Error 'Uhoh!'

# This function will be skipped since second threw an error
third = (name, next) ->
  console.log "#{ name }: third!"

# The queue will know this is an error method since it takes an extra argument
errorHandler = (error, name, next) ->
  console.log error.message
  next error

# This function will be called last after all the queue has been exhausted
done = (error) ->
  console.log if error then  "Something went wrong." else "Success!"

# Call asyncQueue with the args, function queue, and done function
asyncQueue(['Test'], [
  first
  second
  third
  errorHandler
], done)

# Output:
# Test: first!
# Uhoh!
# Something went wrong.

Development

# From the project's dir
npm install && bower install

Build tool

This project uses Gulp.js for it's build tool

To build:

gulp build

To run tests:

gulp test

To build, run tests, and watch for changes:

gulp

Current Tags

  • 1.2.0                                ...           latest (5 years ago)

7 Versions

  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 7
Dependencies (2)
Dev Dependencies (13)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |