{"_id":"@brianmcallister/sequential-promise","_rev":"2-d65910cbedf18657319c2bced7a2872c","name":"@brianmcallister/sequential-promise","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@brianmcallister/sequential-promise","version":"1.0.0","description":"Run Promises that depend on each other sequentially","main":"dist/index.js","repository":{"type":"git","url":"git+https://github.com/brianmcallister/sequential-promise.git"},"license":"MIT","author":{"name":"Brian Wm. McAllister","email":"brian@brianmcallister.com","url":"https://www.brianmcallister.com"},"keywords":["typescript","promise","sequential","serial","dependencies"],"scripts":{"build":"tsc -b --clean && tsc","lint":"eslint ./src/**/* --ext=.ts","prepare":"npm run build","test":"jest --coverage","types":"tsc --noEmit"},"devDependencies":{"@types/jest":"^24.0.25","@types/node":"^13.1.2","@typescript-eslint/eslint-plugin":"^2.14.0","@typescript-eslint/parser":"^2.14.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","eslint":"^6.8.0","jest":"^24.9.0","prettier":"^1.19.1","rimraf":"^3.0.0","ts-jest":"^24.2.0","typescript":"^3.7.4"},"gitHead":"5c455d65cc9fe2a95417482788453a447ed3c2a4","bugs":{"url":"https://github.com/brianmcallister/sequential-promise/issues"},"homepage":"https://github.com/brianmcallister/sequential-promise#readme","_id":"@brianmcallister/sequential-promise@1.0.0","_nodeVersion":"12.13.1","_npmVersion":"6.12.1","dist":{"integrity":"sha512-tQxZI7mmLTMWtIEB0Tj/olIpfgMIL5Pc70PsT2JtnQMcKFLMhAtgUXcIkq/NZ8GqRZ9HBEFainNFGa1fRjRwAw==","shasum":"90a4475aa4b56aa67d486c64a22f8c3067467f7d","tarball":"https://registry.npmjs.org/@brianmcallister/sequential-promise/-/sequential-promise-1.0.0.tgz","fileCount":9,"unpackedSize":17674,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeCoLmCRA9TVsSAnZWagAA9fUP/R6r13MPHIWbmajnnGwp\nBpZ+Zmpu87/loIbUNnJjw8DmodwTxBi6awdV+LxvTbaRZAzQggoCNIQsnyyq\nL69NGJefOjf4m0jqlmx6uJsQ3LpPvSfwcfu3HyiippMG81ngjvLuQX8i04AF\nymmXUKkQfkbSpFRxwKM1zLe5tAAqKh838u7nim7Y+SVt7CGRuX1Vv04Kfcun\nad0NB+0+0aZB9nYkydrql6A0ZVFkshcWOUShKUo5TIcWiDtrjKu5YhrO7Ven\ngDWOHSpAx75L4tePHLMo7xAZRY7h9uoCMuZEXQagae2+fSTgxTA6sFwgq2XE\nnqHMPwkAIpsgVhk/p1bebTZVGxgUWaYanouDSjQ0/1oVGzPHN+RAUuu+L59M\n+8Q+WIq/SvVLyubTL9h/fJIbuIfvLmAdi27Q875h7jNOSVLnceomekr0qffu\n45OIVszwQbgpo064OHGzkJPYQRZ0d/ezoakzddbnBs8YQE4JGx5iuN9N5wY+\nXRdziUp1OFmuavoKDeisVC/KfWS9Q3hVg3C9YXmOILQZhfsFmvePRIRC05Ya\nfgNbhBhO17UWN6C8zMtD1hHK+LCRxEartfs+GpOr0GbmPxPzxD6W0bgtgVBd\nDrQSJ+B3XyT97gXPOsMbyVTQphDeWfWYIrj8Y6oy4jIRX9b7cfTXgWUBS+f3\nvlBx\r\n=W0mJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCq2nd3cavLNg9Y6uBg+BCaEgZ+AxxMDSaO7+jPTmMMzQIhAKvTHQbyURJ/pfXcp3vibAhz/cmPNUFlMCupd5Zf+r5w"}]},"maintainers":[{"name":"brianmcallister","email":"brian@brianmcallister.com"}],"_npmUser":{"name":"brianmcallister","email":"brian@brianmcallister.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequential-promise_1.0.0_1577747173687_0.1461045140354542"},"_hasShrinkwrap":false},"1.0.1":{"name":"@brianmcallister/sequential-promise","version":"1.0.1","description":"Run Promises that depend on each other sequentially","main":"dist/index.js","repository":{"type":"git","url":"git+https://github.com/brianmcallister/sequential-promise.git"},"license":"MIT","author":{"name":"Brian Wm. McAllister","email":"brian@brianmcallister.com","url":"https://www.brianmcallister.com"},"keywords":["typescript","promise","sequential","serial","dependencies"],"scripts":{"build":"tsc -b --clean && tsc","lint":"eslint ./src/**/* --ext=.ts","prepare":"npm run build","test":"jest --coverage","types":"tsc --noEmit"},"devDependencies":{"@types/jest":"^24.0.25","@types/node":"^13.1.2","@typescript-eslint/eslint-plugin":"^2.14.0","@typescript-eslint/parser":"^2.14.0","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","jest":"^25.2.7","prettier":"^1.19.1","rimraf":"^3.0.0","ts-jest":"^25.3.1","typescript":"^3.7.4"},"gitHead":"19bd5fad284a926625b080815ba6a2a2b24903c0","bugs":{"url":"https://github.com/brianmcallister/sequential-promise/issues"},"homepage":"https://github.com/brianmcallister/sequential-promise#readme","_id":"@brianmcallister/sequential-promise@1.0.1","_nodeVersion":"12.13.1","_npmVersion":"6.13.6","dist":{"integrity":"sha512-pB0eIWex0eqZJibxkQTSIe2z591hWPJFvkHDR4haS/Ly9FjwaSmdMrwHDq1KPmgqu3WHW0ZRZZet4LGzdWZb1A==","shasum":"c91fc706f578501b72ec46940e49d925c81563cd","tarball":"https://registry.npmjs.org/@brianmcallister/sequential-promise/-/sequential-promise-1.0.1.tgz","fileCount":9,"unpackedSize":17810,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeiSogCRA9TVsSAnZWagAA2ZEQAIJIwpuEgnlaRt2dr1UI\nN0Ybbhjni0gBf4Eu0P7oyEYwUTDqkD6pJL4bU+3R93pkmo/C2beVFQthzCda\njiJVHGo1txwXe/mcdCLXnbeE4uB0luv0bo2FneRk9QCYPeEyZVjIqUQJfz0H\nP8u8xH2N7Kht8slEj62ZXdRn2vjKY0zvixatWRtzoGD6rcFzgif42qf9CPyB\nK8i99CwkFRjdpLZy0ffPdsfU50UyJJpPTby6EGBAYNY6ulH5aFsNiBkfIg9Z\nkQd0eblVN/3eaE2sHzDHj2ZS6tUl3HCGxrhwX0I1nNnkfkJC/XBwvlOoYlvG\nDMd7nqv/6unv9jrZa9LMLLQHZai0ofOpLgt/PrTS6fgWHIh0Lqtuo6yGRg4Y\nd1Grob/4tVKh9keY4yH0OBtXR+Fn46oXrdTWLUKdFxcflhimBcV8lxrQzvci\nAAtr8D21YmVko6VhFzCt84zv79LifltEa/zEbaBfx/G089HiVED9IheHUEvP\nbifTB6Gllz3I3MsdtOLTstzPHwgihykDKzRy0j7MyvAa77T9STwuYM7vd3G/\n/FIRm8fT2G5HqYaUKoo9isWlZpQGNN5BufCLrVVjdhBu//JBmsEt3L/k6iAN\nOagmcw9ZidwIr/fbnnM5itg8hFj+hjzN03neUxJLaxD0jQGWKzj2g1bt8xhz\nrvMm\r\n=9Mtz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEQUBLAeWoqZxlWBDZPj39qK7sWNDLUje0rIRo4dJ7TEAiEAsfjZ4oXX67CgpTWkkagi2fCMry0LAettey4f6PGaQ4o="}]},"maintainers":[{"name":"brianmcallister","email":"brian@brianmcallister.com"}],"_npmUser":{"name":"brianmcallister","email":"brian@brianmcallister.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequential-promise_1.0.1_1586047519975_0.3852648958645759"},"_hasShrinkwrap":false}},"time":{"created":"2019-12-30T23:06:13.687Z","1.0.0":"2019-12-30T23:06:13.841Z","modified":"2022-04-04T20:32:02.316Z","1.0.1":"2020-04-05T00:45:20.282Z"},"maintainers":[{"name":"brianmcallister","email":"brian@brianmcallister.com"}],"description":"Run Promises that depend on each other sequentially","homepage":"https://github.com/brianmcallister/sequential-promise#readme","keywords":["typescript","promise","sequential","serial","dependencies"],"repository":{"type":"git","url":"git+https://github.com/brianmcallister/sequential-promise.git"},"author":{"name":"Brian Wm. McAllister","email":"brian@brianmcallister.com","url":"https://www.brianmcallister.com"},"bugs":{"url":"https://github.com/brianmcallister/sequential-promise/issues"},"license":"MIT","readme":"# @brianmcallister/sequential-promise\n\n[![codecov](https://codecov.io/gh/brianmcallister/sequential-promise/branch/master/graph/badge.svg)](https://codecov.io/gh/brianmcallister/sequential-promise) [![CircleCI](https://circleci.com/gh/brianmcallister/sequential-promise.svg?style=svg)](https://circleci.com/gh/brianmcallister/sequential-promise) [![npm version](https://img.shields.io/npm/v/@brianmcallister/sequential-promise?label=version&color=%2354C536&logo=npm)](https://www.npmjs.com/package/@brianmcallister/sequential-promise)\n\n> Run Promises that depend on each other sequentially\n\n`sequential-promise` allows for running a series of promises sequentially, where each promise in the list depends on the previous promise having [settled](https://github.com/domenic/promises-unwrapping/blob/master/docs/states-and-fates.md). There are two functions in this package, one that mirrors the behavior of [`Promise#all`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all), and one mirroring [`Promise#allSettled`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) (but which does not require `Promise#allSettled` to exist in your environment).\n\n## Table of contents\n\n<!-- - [Demo](#demo) -->\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n  - Functions\n    - [`sequential`](#sequential)\n    - [`sequentialAllSettled`](#sequentialallsettled)\n  - Types\n    - [`Result<T>`](#resultt)\n\n<!--\n## Demo\n\nHosted demo: [https://sequential-promise.netlify.com/](https://sequential-promise.netlify.com/)\n\nYou can also run the demo locally. To get started:\n\n```sh\ngit clone git@github.com:brianmcallister/sequential-promise.git\ncd sequential-promise/demo\nnpm i\nnpm start\n```\n\n###### [⇡ Top](#table-of-contents)\n-->\n\n## Installation\n\n```sh\nnpm install @brianmcallister/sequential-promise\n```\n\n###### [⇡ Top](#table-of-contents)\n\n## Usage\n\nThe main concept to understand here is that you'll need to create an array of functions that create Promises, not an array of Promises (if you're using TypeScript, then the compiler will yell at you if you pass `Promise<unknown>[]`).\n\nThe functions in this package iterate over the array of functions you pass, calls each one, and then waits for each returned promise settle before continuing on.\n\n```ts\nimport sequential from '@brianmcallister/sequential-promise';\n\nconst asyncRequests = [\n  () => fetchUser({ id: 1 }),\n  (user1) => fetchOrderDetails(user1.orders),\n];\n\nsequential(asyncRequests).then(([user1, userOrderDetails]) => {\n  renderOrderDetails(userOrderDetails);\n});\n\n// ...or with async/await:\nconst [user1, userOrderDetails] = await sequential(asyncRequests);\n\nrenderOrderDetails(userOrderDetails);\n```\n\n###### [⇡ Top](#table-of-contents)\n\n## API\n\n### Functions\n\n#### `sequential`\n\n```ts\nimport sequential from '@brianmcallister/sequential-promise';\n```\n\n`sequential` is the default export. It iterates over an array of functions that return promises. If one of the promises rejects, then everything will stop, and `sequential` will return a rejected promise, just like how [`Promise#all`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all) behaves.\n\n```ts\nsequential: <T>(funcs: ((list: T[]) => Promise<T>)[]) => Promise<T[]>;\n```\n\nAll promises resolving:\n\n```ts\nimport sequential from '@brianmcallister/sequential-promise';\n\nconst promises = [\n  () => Promise.resolve('one'),\n  () => Promise.resolve('two'),\n];\n\nconst results = await sequential(promises);\n// #=> ['one', 'two'];\n```\n\nSome promises rejecting:\n\n```ts\nimport sequential from '@brianmcallister/sequential-promise';\n\nconst promises = [\n  () => Promise.resolve('one'),\n  () => Promise.reject('oops'),\n];\n\ntry {\n  await sequential(promises)\n} catch (err) {\n  console.log(err);\n  // #=> 'oops';\n}\n```\n\n#### `sequentialAllSettled`\n\n```ts\nimport { sequentialAllSettled } from '@brianmcallister/sequential-promise';\n```\n\n`sequentialAllSettled` attempts to behave the same way the forthcoming [`Promise#allSettled](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) behaves.\n\nEven if one of the promises rejects, the iteration won't stop. Instead, the results of every promise are gathered up and the final promise resolves with a summary of all the promises settled values as `Result<T>[]` (See: [`Result<T>`](#resultt) below.\n\n```ts\nsequentialAllSettled: <T>(funcs: ((list: Result<T>[]) => Promise<T>)[]) => Promise<Result<T>[]>;\n```\n\nExample:\n\n```ts\nimport { sequentialAllSettled } from '@brianmcallister/sequential-promise';\n\nconst promises = [\n  () => Promise.resolve('one'),\n  () => Promise.reject('oops'),\n];\n\nconst results = await sequentialAllSettled(promises);\n// #=> [{ status: 'fulfilled', value: 'one' }, { status: 'rejected', reason: 'oops' }];\n```\n\n###### [⇡ Top](#table-of-contents)\n\n### Types\n\n#### `Result<T>`\n\nSettled value when using [`sequentialAllSettled`](#sequentialallsettled).\n\n```ts\nimport { Result } from '@brianmcallister/sequential-promise';\n```\n\n```ts\ninterface Fulfilled<T> {\n    status: 'fulfilled';\n    value: T;\n}\n\ninterface Rejected {\n    status: 'rejected';\n    reason: unknown;\n}\n\ntype Result<T> = Fulfilled<T> | Rejected;\n```\n\n###### [⇡ Top](#table-of-contents)\n","readmeFilename":"README.md"}