1.1.1 • Published 9 years ago

co-foreach v1.1.1

Weekly downloads
1,682
License
MIT
Repository
github
Last release
9 years ago

co-foreach

Build Status

Run generator function as forEach loop callback

Installation

npm install co-foreach

Example 1

var forEach = require('co-foreach');

// Every generator callback is wrapped into co function,
// so you can take advantage of all co features
forEach(array, function * (item, idx) {
  // do something awesome with generators
}).then(handleFinish);

Example 2

var forEach = require('co-foreach');
var Q = require('q');
var fs = require('fs');

var files = ['./test/test1.txt', './test/test2.txt'];

// co-foreach is returning promise
forEach(files, function * (file, idx) {
  var content = yield Q.nfcall(fs.readFile, file);
  // do something usefull
}).then(function () {
  // co-foreach is returning promise which is fulfilled
  // after all generator functions are successfully finished
}).catch(function (err) {
  // handle error
});

Example 3

var forEach = require('co-foreach');

// You can also use co-foreach with normal callbacks
forEach(array, function (item, idx) {
});

License

MIT

1.1.1

9 years ago

1.1.0

9 years ago

1.0.7

9 years ago

1.0.6

11 years ago

1.0.5

11 years ago

1.0.4

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago