0.3.5 • Published 9 years ago

aseq v0.3.5

Weekly downloads
5
License
MIT
Repository
github
Last release
9 years ago

Aseq

Asynchronous Sequence is a javascript library, which deals with the callback hell.

Why Aseq

Without aseq:

a('additional argument', function(err, arg)
{
	if (err != null)
	{
		handleErr(err);
		return;
	}

	arg = change(arg);

	b(arg, function(err, arg)
	{
		if (err != null)
		{
			handleErr(err);
			return;
		}

		arg = change(arg);

		c(arg, function(err, arg)
		{
			if (err != null)
			{
				handleErr(err);
				return;
			}

			arg = change(arg);

			d(arg, function(err, arg)
			{
				if (err != null)
				{
					handleErr(err);
					return;
				}

				arg = change(arg);
			});
		});
	});
});

With aseq (using aseq as object):

var seq = new aseq();

var handleErrors = aseq.createErrorHandler(errorHandler);

seq.append(a);
seq.append(handleErrors);
seq.append(change);

seq.append(b);
seq.append(handleErrors);
seq.append(change);

seq.append(c);
seq.append(handleErrors);
seq.append(change);

seq.append(d);
seq.append(handleErrors);
seq.append(change);

Basic Usage

Aseq as Object

var seq = new aseq();

seq.append(a);
seq.append(b);

seq.run('arg');

Api

seq.append(<function>[, this [, arg ...]])

  1. function - function to be appended
  2. this - object to bind the function to
  3. arg - prefix arguments

Appends a function to the sequence

seq.run([arg ...])

arg - args to pass to the first function in the sequence

Runs the sequence

Aseq as Function Generator

var seq = seq(a, b, c, d);

seq('arg');

Installation

npm install aseq

0.3.5

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago