co-foreach-series
Foreach Series with ES6 generator co.
Last updated a year ago by wenqing.yu .
ISC · Repository · Bugs · Original npm · Tarball
$ cnpm install co-foreach-series 
SYNC missed versions from official npm registry.

co-foreach-series

This foreach-series support for es6 generator function.

co-foreach-series allows you to traverse array elements and process with async task one by one. It's something like Async.forEeachSeries();

However, if you want to go through array element and process async tasks them paralelly with generator, you should take a look of https://github.com/ivpusic/co-foreach.

In this package, we used recursive way to implement loop logic.

Install

npm install co-foreach-series --save

Include

const foreach = require('co-foreach-series');

Example

const foreach = require('co-foreach-series');
const co = require('co');
const request = require("es6-request");

let urls = ['https://github.com/wenqingyu', 'https://github.com/wenqingyu', 'https://github.com/wenqingyu'];
     // array      // element, index
forEach(urls, function(url,    i) {
  return co(function*() {
    let result = yield request.get(url) // async function
    .then((body) => {
      console.log(body);
      return body;
    })

    // wait until async function finished, you can do other process
    return result;
  })
})
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |