{"name":"function-loop","version":"2.0.0","main":"index.js","scripts":{"test":"tap test.js --100"},"repository":{"type":"git","url":"git+https://github.com/isaacs/function-loop.git"},"keywords":[],"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"http://blog.izs.me/"},"license":"ISC","bugs":{"url":"https://github.com/isaacs/function-loop/issues"},"homepage":"https://github.com/isaacs/function-loop#readme","devDependencies":{"tap":"^9.0.3"},"description":"Run a list of functions in order in a given object context.  The functions can be callback-taking or promise-returning.","gitHead":"aff453722f20671f8efdff0d2b17d4a3dfbf1980","_id":"function-loop@2.0.0","_nodeVersion":"15.3.0","_npmVersion":"7.5.4","dist":{"integrity":"sha512-dldE39rrwuoGsF1CCWzmFtwPElKtqAWdSw9n1eXkbdzZLwg4PSggeGFKfK1uytJMKBUaE7PZiQEhH9eQlPJBgA==","shasum":"87fb442ca41124cb58ddb32db4b12c4515fbbfd7","tarball":"http://registry-npm.ywwl.com/function-loop/download/function-loop-2.0.0.tgz","fileCount":14,"unpackedSize":46622,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgK2hZCRA9TVsSAnZWagAAh9gQAIF/tgwZyKa8luHSn2Bl\nCsqrsx8Yr+SSB/VVOD3zMK+TaVu9jsiAxDefAXp/qHXoqjemxDP9KxHskqRC\neQPcHsOASGHABzTayGY7AACXey6U5vWyublzynXJNaXfpaHLSav+MWjRXIMw\ntWlM1hrRM2cyAcEEZVRnrzrKFtKUlrHsrGnHPd0MyhVDWsbGQ+1E4ttJy7P+\nfxSoglfRVep8b523aGBdQYaUqAinSdGHMxs+bt/RsC5N5MiYsXT0y1aHKlCw\nQyTc9TiNgQyRnefr2KabBUHswsvnkwSmh68/JokKCqyLj9aWO+SiAi6Reihq\naT1GwdCpRZ7wNKLAgCkZ6dqfg56S121ST20lrKZI0i//IRS4Xf06uXlayOjl\ngpxzlMAy7y+TcyFPShUiN2VDSWUgKgI5rk59fqWybr0JLJXuGKub0c67Ra4G\n/9zCvHyFi0i1XUXXXxOWBxEp5ZItuF7JicVyfePzqDhOBaiTUew0pFlOKJkn\njVjJBWi6E0/0P1318MXaYVyTGIHWmRNBLSp2OeU3SwH+1iC/R6pJwZarqbYT\nQTN5MgDzJWCW237eDvevohx/avzAfMTKhIFmV96MJGh7+vLr+KMwwh1JczTx\n0b/UoB39aWTGJM19o+wfLCqb3Nihv3hNvG6ulpT717zWYiNqwt2v+bC1hnJs\nP/Z+\r\n=QnYj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAckxZq4+LeJgM8IrqYaiHMJWeFyB9GONKoQ4ZlRPHgpAiAFNVkkcEh8y/6sFKu93te0s7jGlY8rgZZv5sTwKshvVw=="}],"size":15636,"noattachment":false,"key":"/function-loop/-/function-loop-2.0.0.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/function-loop_2.0.0_1613457497152_0.8247033509543569"},"_hasShrinkwrap":false,"readme":"# function-loop\n\nRun a list of synchronous or asynchronous functions, and call a\nfunction at the end.\n\n## USAGE\n\n```ts\nimport { loop } from 'function-loop'\n// or `const { loop } = require('function-loop')\n\nconst loop = require('./dist/cjs/index.js').default\n\n// synchronous usage\nconst list = [\n  () => console.log(1),\n  () => console.log(2),\n  () => console.log(3),\n]\nconst result = loop(list, () => {\n  console.log('done')\n  return true\n}, (er) => {\n  console.error('threw somehow', er)\n})\n\nconsole.log('result:', result)\n// logs:\n// 1\n// 2\n// 3\n// done\n// result: true\n\n// asynchronous usage\nconst plist = [\n  async () => console.log(1),\n  async () => new Promise(resolve => setTimeout(resolve, 100)).then(() =>\n    console.log(2)\n  ),\n  async () => console.log(3),\n]\nconst presult = loop(plist, () => {\n  console.log('done')\n  return true\n}, (er) => {\n  console.error('threw somehow', er)\n})\n\nconsole.log('result:', presult)\npresult.then(() => console.log('resolved'))\n// logs:\n// 1\n// result: Promise { <pending> }\n// 3\n// 2\n// resolved\n```\n\n## Zalgo Preserving\n\nThis module is\n[\"zalgo-preserving\"](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony),\nmeaning that synchronous returns will result in a sync call to\nthe supplied cb, and async calls will result in the done callback\nbeing called asynchronously.  The loop will return a Promise\nindicating when it is finished, if any async functions are\nencountered.  It does not artificially defer if functions are\ncalled synchronously.\n\n## API\n\n`loop(functionList, doneCallback, errorCallback)`\n\nRun all the functions and then call the `doneCallback` or call\nthe `errorCallback` if there are any errors.\n\nFunctions are called without being bound to any object as `this`.\n\nFunctions can return a Promise to do async operations, or not if\nthey are done synchronously.  Throws and Promise rejection are\nreported to the `errorCallback` provided.\n\nReturn value is the return value of the callback, or a `Promise`\nresolving to the callback's return value if any of the functions\nin the list return promises.\n","publish_time":1613457497455,"_cnpm_publish_time":1613457497455,"dist-tags":{"latest":"4.0.0"}}