Q Stuff
$ npm install --save q-ter
var $q = require('q-ter');
$q.map(['foo', 'bar', 'baz'], function(word) {
return word.length;
}).then(function(lengths) {
console.log(Math.max.apply(Math, lengths));
});
$q.reduce(['foo', 'bar', 'baz'], function(agg, word) {
return agg + word.length;
}, 0).then(function(agg_length) {
console.log(agg_length);
});
$q.parallel({
foo: function() {
return 'foo';
},
bar: function() {
var fs = require('fs');
return q.nfcall(fs.readFile('/foo/bar/baz'));
}
}).then(function(data) {
console.log(data.foo, data.bar);
});
$q.auto({
foo: ['bar', function(bar) {
var q = require('q');
return q.delay(2000).then(function() {
return 'foo ' + bar;
});
}],
bar: function() {
return 'I like bars!';
}
}).then(function(data) {
console.log(data.foo, data.bar);
});
var x = 0;
$q.until(function() {
var q = require('q');
return q.delay(1000).then(function() {
x += 1;
});
}, function() {
return x === 10;
}).then(function() {
console.log(x);
});
Runs iterator
until predicate
returns true.
Runs all methods in parallel.