This package has been deprecated

Author message:

No Maintainance. Will be removed by August 31st

domain-async

0.1.2 • Public • Published

Domain-Async

One of the greatest modules oit there is async by Caolan McMahon. I used to use it every day for jsut about everything. While it's great, I did look at the code. It made my eyes hurt. That is probably more due to my sensitive eyes than any failing on Caolan's part, but they still hurt. The other thing is that it's a library, that does just way too much for my tastes. The only functions I really used were series and parallel. Then Node.JS went up to version 0.8 and Domains came along. Domains are absolutely awesome for error handling, and I have fallen in love with them.

So was born the idea for Domain-Async, which tries to be a simple base for doing stuff in series or parallel and have all the tasks each have their own domain. At the same time, I wanted it to be API compatible with async.series and async.parallel.

Status

This is currently being tested. It is likely has so many bugs that it's not even funny.

DO NOT USE THIS ANYWHERE NEAR A PRODUCTION SYSTEM!

You have been warned!

API

Basic Use

var async = require('domain-async');
tasks = [];

async(tasks).done(doneCallback);

function doneCallback(errs, vals) {
  // Go forth and be merry
}

The basic async is a function which accepts 0 or more tasks to execute (arrays of tasks are OK too). It then returns an object with the following methods:

  1. obj.then(task) // adds another task (or array of tasks to be executed)
  2. obj.throttle(count) // limits the maximum number of tasks to run concurrently (default: Number.MAX_VALUE)
  3. obj.progress(function callback(done, running, waiting, total) {}) // provides a way to get notified about progress
  4. obj.done(function callback(errs, vals) {}) // starts the processing and calls callback with the results
  5. obj.values(function callback(vals) {}) // basically the same as done except it ignores errors and returns the array of values
  6. obj.errorStop(function(err, val) {}) // stops on the first error. If it get's through all tasks returns the last value

Async API Compatibility

In order to be API compatible with async, there are 2 functions on the basic module.

  1. async.series(tasks, callback)
  2. async.parallel(tasks, callback)

async.series

This is implemented as:

function series(tasks, callback) {
  tasks = concurrent(tasks)
  tasks = tasks.throttle(1);
  tasks.errorStop(callback);
}

async.parallel

This is implemented as:

function parallel(tasks, callback) {
  tasks = concurrent(tasks);
  tasks.done(callback);
}

async.*

In addition to series and parallel there are these:

  • async.map(items, fn, callback)
  • async.mapSeries(items, fn, callback)
  • async.filter(items, fn, callback)
  • async.filterSeries(items, fn, callback)
  • async.forEach(items, iter, callback)
  • async.forEachSeries(items, iter, callback)
  • async.detect(arr, iterator, callback)
  • async.detectSeries(arr, iterator, callback)
  • async.sortBy(items, iter, callback)
  • async.reject(items, iter, callback)
  • async.rejectSeries(arr, iterator, callback)

However since I don't use them on a regular basis, these will suffer from less testing !

License

MIT License

Copyright (C) 2012 YOUSURE Tarifvergleich GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i domain-async

Weekly Downloads

4

Version

0.1.2

License

none

Last publish

Collaborators

  • dbnpm