Skip to content

mattinsler/q-ter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

q-ter

Q Stuff

Installation

$ npm install --save q-ter

Usage

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);
});

Methods

$q.until(iterator, predicate)

Runs iterator until predicate returns true.

$q.parallel(config)

Runs all methods in parallel.

$q.auto(config)