{"name":"function-loop","version":"2.0.1","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":"133740eb47b70ac6306360d7df303e546b954217","_id":"function-loop@2.0.1","_nodeVersion":"15.3.0","_npmVersion":"7.5.4","dist":{"integrity":"sha512-ktIR+O6i/4h+j/ZhZJNdzeI4i9lEPeEK6UPR2EVyTVBqOwcU3Za9xYKLH64ZR9HmcROyRrOkizNyjjtWJzDDkQ==","shasum":"799c56ced01698cf12a1b80e4802e9dafc2ebada","tarball":"http://registry-npm.ywwl.com/function-loop/download/function-loop-2.0.1.tgz","fileCount":3,"unpackedSize":2385,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgK2kFCRA9TVsSAnZWagAALj8QAJT7GiySCa7eC2pysPNd\nSMMnanOPNjM0V0HZhAEsycfCCGNloMmRdSpInPczlFhGZfHWnhHO0CLFRLW8\nabPY10uuxWntkj59Xe1OfjcV3a3HB09lEZYOXMr7cnnJH/EbnOiRVroiCs72\nDzulTW+n+TpegiMgyAs3AVXzPMwriFDAl5jA+eBc1BaiFNr0Ba4CxLiIME9j\nmEc3Ln/pXUUgLQ3nwFhml7G7EGMF3a5WhSoyL8pF7b6pvTAKn4aUa2u9Tewd\n9sOBmnbIa2nrjqcnIySgE3XrLuIxtQyGG0rmWkm2S5LaAO5+zHCGKtanL1uQ\ntrx0e06MA3EmrHu3LQyskogBZ+vcMCGvnwE0lYffOFHAVjAt7Lw6eUPoKQXK\nPbvK8RbyJcn44l/Ore+4z1wWKzExLIIiXyCnD3azNm4QvdZCf0ADk5ivOzBc\np6sCVRcag9Vu/2nPXVIazEjHoKd8fTlN8CZN9nNpGKduSj1X+dgd4sJzo/7J\nqAgJwjRhe3q8+yy0huxyU4BLYL+zSiVY22qt9b+4JJAOpXwagmenOfAOGTBl\nNYlBMQK71ROSdJp2JvdCALwiUs9XLC8nb2+E42LF+Ro+rJQeHoK9ZtFi8TSk\nLLm/KHmrMsWm+aaWo6dExyKcdoIsd1anHr2I3z5Tt7BFp0Nk2vWrrUcB8gm4\n5tKc\r\n=R8vD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD6rxReQoU8jnI29ZDi1g0IFbgUYafSDvU60BEklibvNwIgH6ZeGJ3QN/9eZ0h0izmNi36lfkKgjocTX5RvEPIJr9Y="}],"size":1250,"noattachment":false,"key":"/function-loop/-/function-loop-2.0.1.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.1_1613457669060_0.2951134278171881"},"_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":1613457669231,"_cnpm_publish_time":1613457669231,"dist-tags":{"latest":"4.0.0"}}