{"id":13448596,"url":"https://github.com/sindresorhus/p-progress","last_synced_at":"2025-05-15T14:04:18.619Z","repository":{"id":48317895,"uuid":"103123260","full_name":"sindresorhus/p-progress","owner":"sindresorhus","description":"Create a promise that reports progress","archived":false,"fork":false,"pushed_at":"2023-11-04T14:35:59.000Z","size":36,"stargazers_count":767,"open_issues_count":1,"forks_count":25,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-12T03:25:32.117Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/sindresorhus.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},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2017-09-11T10:36:43.000Z","updated_at":"2025-04-06T09:52:42.000Z","dependencies_parsed_at":"2023-12-19T05:25:03.993Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/p-progress","commit_stats":{"total_commits":33,"total_committers":9,"mean_commits":"3.6666666666666665","dds":0.3939393939393939,"last_synced_commit":"12d4222ab51b53016cd3574e41e4361a562a915b"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-progress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-progress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-progress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-progress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/p-progress/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254355334,"owners_count":22057354,"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":[],"created_at":"2024-07-31T05:01:49.964Z","updated_at":"2025-05-15T14:04:18.596Z","avatar_url":"https://github.com/sindresorhus.png","language":"TypeScript","readme":"# p-progress\n\n\u003e Create a promise that reports progress\n\nUseful for reporting progress to the user during long-running async operations.\n\n## Install\n\n```sh\nnpm install p-progress\n```\n\n## Usage\n\n```js\nimport pProgress from 'p-progress';\n\nconst runJob = async name =\u003e pProgress(async progress =\u003e {\n\tconst job = new Job(name);\n\n\tjob.on('data', data =\u003e {\n\t\tprogress(data.length / job.totalSize);\n\t});\n\n\tawait job.run();\n});\n\nconst progressPromise = runJob('Gather rainbows');\n\nprogressPromise.onProgress(console.log);\n//=\u003e 0.09\n//=\u003e 0.23\n//=\u003e 0.59\n//=\u003e 0.75\n//=\u003e 1\n\nawait progressPromise;\n```\n\n## API\n\n### pProgress(function)\n\nConvenience method to make your promise-returning or async function report progress.\n\nThe function you specify will be passed the `progress()` function as a parameter.\n\n### instance = new PProgress(executor)\n\nSame as the [`Promise` constructor](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), but with an appended `progress` parameter in `executor`.\n\n`PProgress` is a subclass of `Promise`.\n\n###### progress(percentage)\n\nType: `Function`\n\nCall this with progress updates. It expects a number between 0 and 1.\n\nMultiple calls with the same number will result in only one `onProgress()`\nevent.\n\nCalling with a number lower than previously will be ignored.\n\nProgress percentage `1` is reported for you when the promise resolves. If you set it yourself, it will simply be ignored.\n\n#### instance.progress\n\nType: `number`\n\nThe current progress percentage of the promise as a number between 0 and 1.\n\n#### instance.onProgress(function)\n\nAccepts a function that gets `instance.progress` as an argument and is called for every progress event.\n\n```js\nimport {PProgress} from 'p-progress';\n\nconst progressPromise = new PProgress((resolve, reject, progress) =\u003e {\n\tconst job = new Job();\n\n\tjob.on('data', data =\u003e {\n\t\tprogress(data.length / job.totalSize);\n\t});\n\n\tjob.on('finish', resolve);\n\tjob.on('error', reject);\n});\n\nprogressPromise.onProgress(progress =\u003e {\n\tconsole.log(`${progress * 100}%`);\n\t//=\u003e 9%\n\t//=\u003e 23%\n\t//=\u003e 59%\n\t//=\u003e 75%\n\t//=\u003e 100%\n});\n\nawait progressPromise;\n```\n\n### PProgress.all(promises, options?)\n\nConvenience method to run multiple promises and get a total progress of all of them. It counts normal promises with progress `0` when pending and progress `1` when resolved. For `PProgress` type promises, it listens to their `onProgress()` method for more fine grained progress reporting. You can mix and match normal promises and `PProgress` promises.\n\n### PProgress.allSettled(promises, options?)\n\nLike [`Promise.allSettled`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) but also exposes the total progress of all of the promises like `PProgress.all`.\n\n```js\nimport pProgress, {PProgress} from 'p-progress';\nimport delay from 'delay';\n\nconst progressPromise = () =\u003e pProgress(async progress =\u003e {\n\tprogress(0.14);\n\tawait delay(52);\n\tprogress(0.37);\n\tawait delay(104);\n\tprogress(0.41);\n\tawait delay(26);\n\tprogress(0.93);\n\tawait delay(55);\n\treturn 1;\n});\n\nconst progressPromise2 = () =\u003e pProgress(async progress =\u003e {\n\tprogress(0.14);\n\tawait delay(52);\n\tprogress(0.37);\n\tawait delay(104);\n\tprogress(0.41);\n\tawait delay(26);\n\tprogress(0.93);\n\tawait delay(55);\n\tthrow new Error('Catch me if you can!');\n});\n\nconst allProgressPromise = PProgress.allSettled([\n\tprogressPromise(),\n\tprogressPromise2()\n]);\n\nallProgressPromise.onProgress(console.log);\n//=\u003e 0.0925\n//=\u003e 0.3425\n//=\u003e 0.5925\n//=\u003e 0.6025\n//=\u003e 0.7325\n//=\u003e 0.9825\n//=\u003e 1\n\nconsole.log(await allProgressPromise);\n//=\u003e [{status: 'fulfilled', value: 1}, {status: 'rejected', reason: Error: Catch me if you can!}]\n```\n\n#### promises\n\nType: `Promise[]`\n\nAn array of promises or promise-returning functions, similar to [p-all](https://github.com/sindresorhus/p-all).\n\n#### options\n\nType: `object`\n\n##### concurrency\n\nType: `number`\\\nDefault: `Infinity`\\\nMinimum: `1`\n\nThe number of concurrently pending promises.\n\nTo run the promises in series, set it to `1`.\n\nWhen this option is set, the first argument must be an array of promise-returning functions.\n\n## Related\n\n- [p-cancelable](https://github.com/sindresorhus/p-cancelable) - Create a promise that can be canceled\n- [More…](https://github.com/sindresorhus/promise-fun)\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["TypeScript","Packages","📦 Legacy \u0026 Inactive Projects","others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-progress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fp-progress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-progress/lists"}