0.3.5 • Published 9 years ago
aseq v0.3.5
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 ...]])
function
- function to be appendedthis
- object to bind the function toarg
- 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