{"id":16487383,"url":"https://github.com/tjenkinson/promise-chain-settled","last_synced_at":"2025-04-08T06:44:55.327Z","repository":{"id":37825742,"uuid":"276481436","full_name":"tjenkinson/promise-chain-settled","owner":"tjenkinson","description":"Provides a way of knowing when a promise chain is settled. Useful for testing.","archived":false,"fork":false,"pushed_at":"2024-03-29T18:06:15.000Z","size":570,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T20:06:49.977Z","etag":null,"topics":["fulfilled","promise","promise-chain","rejected","resolved","settled","testing"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tjenkinson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-07-01T21:03:48.000Z","updated_at":"2023-03-04T04:25:13.000Z","dependencies_parsed_at":"2024-03-29T19:25:55.785Z","dependency_job_id":"c86ee130-2daf-4ce5-848f-fb5c5f1963ae","html_url":"https://github.com/tjenkinson/promise-chain-settled","commit_stats":{"total_commits":199,"total_committers":4,"mean_commits":49.75,"dds":"0.11557788944723613","last_synced_commit":"829db2cc1f17a553c58e8fef426db9c5d3a00dd1"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjenkinson%2Fpromise-chain-settled","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjenkinson%2Fpromise-chain-settled/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjenkinson%2Fpromise-chain-settled/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjenkinson%2Fpromise-chain-settled/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tjenkinson","download_url":"https://codeload.github.com/tjenkinson/promise-chain-settled/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247451644,"owners_count":20940939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fulfilled","promise","promise-chain","rejected","resolved","settled","testing"],"created_at":"2024-10-11T13:34:02.267Z","updated_at":"2025-04-08T06:44:55.283Z","avatar_url":"https://github.com/tjenkinson.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/promise-chain-settled.svg)](https://badge.fury.io/js/promise-chain-settled)\n\n# promise-chain-settled\n\nProvides a way of knowing when a promise chain is settled. Useful for testing.\n\n## Installation\n\n```sh\nnpm install --save promise-chain-settled\n```\n\nor available on JSDelivr at \"https://cdn.jsdelivr.net/npm/promise-chain-settled@1\".\n\n## API\n\nFirst you need to wrap the promise with `wrap(promise)`.\n\nThis returns an object with the following properties:\n\n### numPending(): number\n\nThis returns the number of promises in the chain that are currently pending. It can increase at any time if new items are added.\n\n```ts\nconst promise = new Promise(() =\u003e {});\nconst wrapped = wrap(promise);\nconsole.log(wrapped.numPending()); // 1\npromise.then(() =\u003e {});\nconsole.log(wrapped.numPending()); // 2\n```\n\n### isChainSettled(): boolean\n\nReturns `true` when `numPending() === 0` meaning everything in the chain is settled. This can change at any time if new items are added.\n\n```ts\nconst promise = Promise.resolve();\nconst wrapped = wrap(promise);\nconsole.log(wrapped.isChainSettled()); // false\nawait promise;\nconsole.log(wrapped.isChainSettled()); // true\npromise.then(() =\u003e {});\nconsole.log(wrapped.isChainSettled()); // false\n```\n\n### whenChainSettled(): Promise\u003cvoid\u003e\n\nThis returns a promise that resolves the next time `isChainSettled()` goes from `false` to `true`.\n\n### onChange(listener: () =\u003e void): { remove: () =\u003e void }\n\nThis lets you add a listener that will be invoked whenever `numPending()` changes.\n\n```ts\nconst promise = Promise.resolve();\nconst wrapped = wrap(promise);\nwrapped.onChange(() =\u003e {\n  // first call: new numPending() 2\n  // second call: new numPending() 1\n  // third call: new numPending() 0\n  console.log('new numPending()', wrapped.numPending());\n});\npromise.then(() =\u003e {});\n```\n\n## Example\n\n```ts\nimport { wrap } from 'promise-chain-settled';\n\nconst promise = Promise.resolve();\n\n// modify the promise so that we can keep track of everything in the chain\nconst wrapped = wrap(promise);\n\npromise\n  .then(() =\u003e {\n    return somethingAsync();\n  })\n  .then(() =\u003e {\n    return somethingElseAsync();\n  })\n  .then((something) =\u003e {\n    console.log('Done');\n  });\n\nwrapped.whenChainSettled().then(() =\u003e {\n  console.log('Chain settled');\n});\n```\n\nwould log\n\n```\nDone\nChain settled\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjenkinson%2Fpromise-chain-settled","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftjenkinson%2Fpromise-chain-settled","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjenkinson%2Fpromise-chain-settled/lists"}