iterator-async

2018-09-26 admin

iterator-async是什么

什么是iterator-async,Iterate over a stack of async functions.

iterator-async使用教程帮助文档

iterator-async NPM version Build Status

Iterate over a stack of async functions.

This module is intended to be used with loader-cachebut may be used by itself or in other modules.

Install with npm

$ npm i iterator-async --save

Usage

var iterator = require('iterator-async');

API

iterator

Iterate over a stack of async functions passing the results of each function to the next function in the stack.

Params

  • stack {Array}: Array of functions to call.
  • returns {Function}: Returns a function that will iterator over the given stack of functions.
var fs = require('fs');
var iterator = require('iterator-async');
var stack = [
  function (fp, next) { return fs.readFile(fp, 'utf8', next); },
  function (contents, next) { return next(null, JSON.parse(contents)); }
];
var readJSON = iterator(stack);
readJSON('./package.json', function (err, pkg) {
  if (err) console.error(err);
  console.log(pkg);
});

Related projects

  • async: Higher-order functions and common patterns for asynchronous code
  • iterator-promise: Iterator over a stack of functions.
  • iterator-streams: Iterator over a stack of functions.
  • iterator-sync: Iterator over a stack of functions.
  • loader-cache: Register loader functions that dynamically read, parse or otherwise transform file contents when the name… more

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Brian Woodward

License

Copyright © 2015 Brian Woodward Released under the MIT license.


This file was generated by verb-cli on June 17, 2015.

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-41263.html

文章标题:iterator-async

回到顶部