nak-js
v0.0.2
Published
Simple and expressive control flow library for asynchronous code
Downloads
5
Readme
nak-js
Nak-js is an asynchronous control flow library that aims to be expressive and simple.
Install
npm install nak-js
Quick Examples
Parallel
var onDone = parallel(2, function () {
console.log('done');
});
setTimeout(onDone, 1000);
setTimeout(onDone, 3000);
// or
var numbers = [1,2,3,4,5];
var onDone = parallel(numbers.length, function () {
console.log('done');
});
numbers.forEach(function () {
setTimeout(onDone, 1000);
});
each
var total = 0;
each(function (number, next) {
console.log(number);
total += number;
setTimeout(next, 1000);
}).
from([1,2,3,4,5, 6]).
done(function (err) {
console.log(total);
});
repeate
var count = 0;
repeate(function (next) {
count++;
setTimeout(next, 1000);
}).
until(function (next) {
next(count < 5);
}).
done(function (err) {
console.log(count);
});