{"id":18304552,"url":"https://github.com/numtel/progress-promise","last_synced_at":"2025-04-05T15:31:20.795Z","repository":{"id":57331039,"uuid":"57356273","full_name":"numtel/progress-promise","owner":"numtel","description":"Promise subclass with mechanism to report progress before resolving","archived":false,"fork":false,"pushed_at":"2024-05-15T22:22:37.000Z","size":8,"stargazers_count":25,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T06:33:29.363Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/numtel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2016-04-29T05:12:11.000Z","updated_at":"2024-11-13T07:47:32.000Z","dependencies_parsed_at":"2024-06-18T21:34:30.640Z","dependency_job_id":"1bec58fe-c939-48d2-af3f-e10ba752f899","html_url":"https://github.com/numtel/progress-promise","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":"0.11111111111111116","last_synced_commit":"25d4b169c74c32fa0cdcb87b94c94e1b2349f62a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fprogress-promise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fprogress-promise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fprogress-promise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fprogress-promise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/numtel","download_url":"https://codeload.github.com/numtel/progress-promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247358636,"owners_count":20926262,"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-11-05T15:29:19.462Z","updated_at":"2025-04-05T15:31:18.492Z","avatar_url":"https://github.com/numtel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# progress-promise [![Build Status](https://travis-ci.org/numtel/progress-promise.svg?branch=master)](https://travis-ci.org/numtel/progress-promise) [![npm version](https://badge.fury.io/js/progress-promise.svg)](https://www.npmjs.com/package/progress-promise)\n\nPromise subclass with mechanism to report progress before resolving\n\n## class ProgressPromise extends Promise\n\n### constructor(executor)\n* `executor` `\u003cFunction\u003e` Invoked immediately\n  * `resolve` `\u003cFunction\u003e` Same as original `Promise`\n  * `reject` `\u003cFunction\u003e` Same as original `Promise`\n  * `progress` `\u003cFunction\u003e` Before resolving, pass single argument to progress listener (May be invoked multiple times)\n\nExecutor function receives extra argument: `progress`, a function to be called to notify a listener before resolving.\n\n```javascript\nconst ProgressPromise = require('progress-promise');\n\nfunction longTask() {\n  return new ProgressPromise((resolve, reject, progress) =\u003e {\n    setTimeout(() =\u003e progress(25), 250);\n    setTimeout(() =\u003e progress(50), 500);\n    setTimeout(() =\u003e progress(75), 750);\n    setTimeout(resolve, 1000);\n  });\n}\n```\n\n### progress(handler)\n* `handler` `\u003cFunction\u003e` Invoked by `progress` function passed to `executor`\n  * `value` `\u003cFunction\u003e` Value from `executor`\n\nPromise rejects if progress handler throws.\n\n```javascript\nlongTask()\n  .progress(value =\u003e console.log(value + '%'))\n  .then(() =\u003e console.log('Done'));\n\n// 25%\n// 50%\n// 75%\n// Done\n```\n\n### static all(promises)\n* `promises` `\u003cArray(Promise)\u003e` Array of Promise, or compatible\n\nLike `Promise.all()` but the results are passed to the `progress` listener as an `Array` after each completion.\n\nA custom property, `proportion` is added to this results array containing the value of the number of Promises resolved divided by the total number of Promises.\n\n```javascript\nfunction delay(duration) {\n  return new Promise(resolve =\u003e\n    setTimeout(() =\u003e resolve(duration), duration));\n}\n\nProgressPromise.all([ delay(300), delay(100) ])\n  .progress(results =\u003e console.log('Progress', results))\n  .then(results =\u003e console.log('Resolved', results));\n\n// Progress [ , 100, proportion: 0.5 ]\n// Progress [ 300, 100, proportion: 1 ]\n// Resolved [ 300, 100, proportion: 1 ]\n```\n\n### static sequence(inputs, handler)\n* `inputs` `\u003cArray\u003e` Input values to be passed to `handler` sequentially\n* `handler` `\u003cFunction\u003e` Invoked for each input value, must return Promise\n  * `value` From `inputs` array\n\nHandler is invoked once for each input value, starting with the first index and proceding after each Promise returned resolves.\n\nProgress is reported the same as `ProgressPromise.all()`.\n\n```javascript\nProgressPromise.sequence([ 200, 100 ], value =\u003e delay(value))\n  .progress(results =\u003e console.log('Progress', results))\n  .then(results =\u003e console.log('Resolved', results));\n\n// Progress [ 200, proportion: 0.5 ]\n// Progress [ 200, 100, proportion: 1 ]\n// Resolved [ 200, 100, proportion: 1 ]\n```\n\n## Design Considerations\n\n### Single argument for progress listeners\n\nThe function that invokes each listener on progress updates only has a single argument available due to the lack of support for spread operators in the target Node.js version this package aims to support, 4.3.\n\n```javascript\nvalue =\u003e this[LISTENERS].forEach(listener =\u003e listener(value))\n```\nIf a normal (not arrow) function is used here, `this` cannot be accessed before `super()` is called, making it impossible to bind to the listeners instance property.\n\n### Symbols as private properties\n\nThe new ES6 `Symbol()` type creates a non-enumerating value that can be used as a key on an object. Creating a key on an object instance with a Symbol can be similar to creating a private property if the Symbol is not shared. If Symbols are not available, a fallback string property key is used.\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fprogress-promise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumtel%2Fprogress-promise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fprogress-promise/lists"}