chain-tinyにwaitとeach(Parallel)追加

ほしかったので追加。eachはforEachのObject版。waitはjsdeferredのwaitとほぼ同じ(引数はms)

こんな感じ。

var chain = require('chain-tiny');

// each
chain(function(next) {
  next(null, { foo: 'bar', hoge: 'fuga'});
})
.each(function(key, val, next) {
  setTimeout(function() {
    next(null, key + ':' + val);
  }, 1);
})
.end(function(err, results) {
  console.log(results); // => { foo: 'foo:bar', hoge: 'hoge:fuga' }
});

// chain.each
chain.each({ foo: 'bar', hoge: 'fuga'}, function(key, val, next) {
  setTimeout(function() {
    next(null, key + ':' + val);
  }, 1);
})
.end(function(err, results) {
  console.log(results); // => { foo: 'foo:bar', hoge: 'hoge:fuga' }
});

// wait
chain(function(next) {
  next(null, 'foo', 'bar');
})
.wait(100) // wait 100ms
.chain(function(foo, bar, next) {
  console.log(foo) // => 'foo'
  console.log(bar) // => 'bar'
  next();
})
.end(function(err) {
  //...
});

並列版のeachParallelも追加してる。なんかtinyじゃなくなってきた気もする。。