{"name":"now-and-later","version":"0.0.3","description":"Series/parallel execution of async functions with extension points","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"https://github.com/phated/now-and-later"},"keywords":["async","extension","tracing","debug","aop"],"author":{"name":"Blaine Bublitz","email":"blaine@iceddev.com","url":"http://iceddev.com/"},"license":"MIT","bugs":{"url":"https://github.com/phated/now-and-later/issues"},"homepage":"https://github.com/phated/now-and-later","dependencies":{"async-done":"^0.3.0"},"gitHead":"34e855e8a9c4a9473f56aeb0b972a74875d0e238","_id":"now-and-later@0.0.3","_shasum":"345eed9d15c2d5fa0e26968ed2c5c101ff51cdae","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"phated","email":"blaine@iceddev.com"},"maintainers":[{"name":"phated","email":"blaine@iceddev.com"}],"dist":{"shasum":"345eed9d15c2d5fa0e26968ed2c5c101ff51cdae","tarball":"http://registry-npm.ywwl.com/now-and-later/download/now-and-later-0.0.3.tgz","integrity":"sha512-6OS74D8zgAuZUMlQ7CIQZJcmxLRg7Fm6W9mp4dT0Sn6hqBqdjY8ymto4Va+DeWT0dd6QkXcrCXxXgwKFA4TyBg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHrxyminO7NM05gZzRN+3L2enPSyb51xnU1/n2O0oREbAiB5Fy/oPpXjM3C1H0V8o8guOGQ5DO+83KXUmytjB3+XwA=="}],"size":2911,"noattachment":false,"key":"/now-and-later/-/now-and-later-0.0.3.tgz"},"directories":{},"readme":"<p align=\"center\">\n  <a href=\"https://gulpjs.com\">\n    <img height=\"257\" width=\"114\" src=\"https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png\">\n  </a>\n</p>\n\n# now-and-later\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]\n\nMap over an array or object of values in parallel or series, passing each through the async iterator, with optional lifecycle hooks.\n\n## Usage\n\n```js\nvar nal = require('now-and-later');\n\nfunction iterator(value, key, cb) {\n  // called with each value in sequence\n  // also passes the key\n  cb(null, value * 2);\n}\n\nfunction create(value, key) {\n  // called at the beginning of every iteration\n  // return a storage object to be passed to each lifecycle method\n  return { key: key, value: value };\n}\n\nfunction before(storage) {\n  // called before the iterator function of every iteration\n  // receives the storage returned from `create`\n}\n\nfunction after(result, storage) {\n  // called after a success occurs in the iterator function of any iteration\n  // receives the `result` of the iterator and the storage returned from `create`\n}\n\nfunction error(error, storage) {\n  // called after an error occurs in the iterator function of any iteration\n  // receives the `error` of the iterator and the storage returned from `create`\n}\n\nfunction done(error, results) {\n  // called after all iterations complete or an error occurs in an iterator\n  // receives an `error` if one occurred and all results (or partial results upon error) of the iterators\n}\n\n/*\n  Calling mapSeries with an object can't guarantee order\n  It uses Object.keys to get an order\n  It is better to use an array if order must be guaranteed\n */\nnal.mapSeries(\n  [1, 2, 3],\n  iterator,\n  {\n    create: create,\n    before: before,\n    after: after,\n    error: error,\n  },\n  done\n);\n\nnal.map(\n  {\n    iter1: 1,\n    iter2: 2,\n  },\n  iterator,\n  {\n    create: create,\n    before: before,\n    after: after,\n    error: error,\n  },\n  done\n);\n```\n\n## API\n\n### `map(values, iterator[, options][, callback])`\n\nTakes an object or array of `values` and an `iterator` function to execute with each value.\nOptionally, takes an `options` object and a `callback` function that is called upon completion of the iterations.\n\nAll iterations run in parallel.\n\n#### `values`\n\nAn array or object of values to iterate over.\n\nIf `values` is an array, iterations are started in order by index. If `values` is an object, iterations are started in order by the order returned by `Object.keys` (order is not guaranteed).\n\nIf `values` is an array, the results of each iteration will be mapped to an array. If `values` is an object, the results of each iteration will be mapped to an object with corresponding keys.\n\n#### `iterator(value, key, done)`\n\nAn async function called per iteration. All iterations are run in parallel.\n\nThe `iterator` function is called once with each `value`, `key` and a function (`done(error, result)`) to call when the async work is complete.\n\nIf `done` is passed an error as the first argument, the iteration will fail and the sequence will be ended; however, any iterations in progress will still complete. If `done` is passed a `result` value as the second argument, it will be added to the final results array or object.\n\n#### `options`\n\nThe `options` object is primarily used for specifying functions that give insight into the lifecycle of each iteration. The possible extension points are `create`, `before`, `after` and `error`. If an extension point is not specified, it defaults to a no-op function.\n\nThe `options` object for `map` also allows specifying `concurrency` in which to run your iterations. By default, your iterations will run at maximum concurrency.\n\n##### `options.concurrency`\n\nLimits the amount of iterations allowed to run at a given time.\n\n##### `options.create(value, key)`\n\nCalled at the very beginning of each iteration with the `value` being iterated and the `key` from the array or object. If `create` returns a value (`storage`), it is passed to the `before`, `after` and `error` extension points.\n\nIf a value is not returned, an empty object is used as `storage` for each other extension point.\n\nThis is useful for tracking information across an iteration.\n\n##### `options.before(storage)`\n\nCalled immediately before each iteration with the `storage` value returned from the `create` extension point.\n\n##### `options.after(result, storage)`\n\nCalled immediately after each iteration with the `result` of the iteration and the `storage` value returned from the `create` extension point.\n\n##### `options.error(error, storage)`\n\nCalled immediately after a failed iteration with the `error` of the iteration and the `storage` value returned from the `create` extension point.\n\n#### `callback(error, results)`\n\nA function that is called after all iterations have completed or one iteration has errored.\n\nIf all iterations completed successfully, the `error` argument will be empty and the `results` will be a mapping of the `iterator` results.\n\nIf an iteration errored, the `error` argument will be passed from that iteration and the `results` will be whatever partial results had completed successfully before the error occurred.\n\n### `mapSeries(values, iterator[, options][, callback])`\n\nTakes an object or array of `values` and an `iterator` function to execute with each value.\nOptionally, takes an `options` object and a `callback` function that is called upon completion of the iterations.\n\nAll iterations run in serial.\n\n#### `values`\n\nAn array or object of values to iterate over.\n\nIf `values` is an array, iterations are started in order by index. If `values` is an object, iterations are started in order by the order returned by `Object.keys` (order is not guaranteed).\n\nIf `values` is an array, the results of each iteration will be mapped to an array. If `values` is an object, the results of each iteration will be mapped to an object with corresponding keys.\n\n#### `iterator(value, key, done)`\n\nAn async function called per iteration. All iterations are run in serial.\n\nThe `iterator` function is called once with each `value`, `key` and a function (`done(error, result)`) to call when the async work is complete.\n\nIf `done` is passed an error as the first argument, the iteration will fail and the sequence will be ended without executing any more iterations. If `done` is passed a `result` value as the second argument, it will be added to the final results array or object.\n\n#### `options`\n\nThe `options` object is primarily used for specifying functions that give insight into the lifecycle of each iteration. The possible extension points are `create`, `before`, `after` and `error`. If an extension point is not specified, it defaults to a no-op function.\n\n##### `options.create(value, key)`\n\nCalled at the very beginning of each iteration with the `value` being iterated and the `key` from the array or object. If `create` returns a value (`storage`), it is passed to the `before`, `after` and `error` extension points.\n\nIf a value is not returned, an empty object is used as `storage` for each other extension point.\n\nThis is useful for tracking information across an iteration.\n\n##### `options.before(storage)`\n\nCalled immediately before each iteration with the `storage` value returned from the `create` extension point.\n\n##### `options.after(result, storage)`\n\nCalled immediately after each iteration with the `result` of the iteration and the `storage` value returned from the `create` extension point.\n\n##### `options.error(error, storage)`\n\nCalled immediately after a failed iteration with the `error` of the iteration and the `storage` value returned from the `create` extension point.\n\n#### `callback(error, results)`\n\nA function that is called after all iterations have completed or one iteration has errored.\n\nIf all iterations completed successfully, the `error` argument will be empty and the `results` will be a mapping of the `iterator` results.\n\nIf an iteration errored, the `error` argument will be passed from that iteration and the `results` will be whatever partial results had completed successfully before the error occurred.\n\n## License\n\nMIT\n\n<!-- prettier-ignore-start -->\n[downloads-image]: https://img.shields.io/npm/dm/now-and-later.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/now-and-later\n[npm-image]: https://img.shields.io/npm/v/now-and-later.svg?style=flat-square\n\n[ci-url]: https://github.com/gulpjs/now-and-later/actions?query=workflow:dev\n[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/now-and-later/dev?style=flat-square\n\n[coveralls-url]: https://coveralls.io/r/gulpjs/now-and-later\n[coveralls-image]: https://img.shields.io/coveralls/gulpjs/now-and-later/master.svg?style=flat-square\n<!-- prettier-ignore-end -->\n","publish_time":1408336681999,"_cnpm_publish_time":1408336681999,"dist-tags":{"latest":"3.0.0"}}