{"id":20961660,"url":"https://github.com/elchininet/get-promisable-result","last_synced_at":"2025-05-14T07:30:55.446Z","repository":{"id":262018756,"uuid":"885991658","full_name":"elchininet/get-promisable-result","owner":"elchininet","description":"A very small JavaScript utility to check and retry a function a limited number of times abstracting it in a Promise","archived":false,"fork":false,"pushed_at":"2025-05-04T13:31:06.000Z","size":406,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-04T14:28:17.379Z","etag":null,"topics":["async","async-result","check-and-retry","javascript","javascript-utility","promisable","promisable-result","promise","retry","utility"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/elchininet.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":"elchininet"}},"created_at":"2024-11-09T22:37:09.000Z","updated_at":"2025-05-04T13:31:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"3f91b97c-15ea-4687-862c-81663ab422a2","html_url":"https://github.com/elchininet/get-promisable-result","commit_stats":null,"previous_names":["elchininet/get-promisable-result"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elchininet%2Fget-promisable-result","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elchininet%2Fget-promisable-result/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elchininet%2Fget-promisable-result/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elchininet%2Fget-promisable-result/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elchininet","download_url":"https://codeload.github.com/elchininet/get-promisable-result/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254094819,"owners_count":22013648,"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":["async","async-result","check-and-retry","javascript","javascript-utility","promisable","promisable-result","promise","retry","utility"],"created_at":"2024-11-19T02:15:10.718Z","updated_at":"2025-05-14T07:30:55.062Z","avatar_url":"https://github.com/elchininet.png","language":"TypeScript","funding_links":["https://github.com/sponsors/elchininet"],"categories":[],"sub_categories":[],"readme":"# get-promisable-result\n\nA very small JavaScript utility to check and retry a function a limited number of times abstracting it in a Promise\n\n[![Deployment Status](https://github.com/elchininet/get-promisable-result/actions/workflows/deploy.yaml/badge.svg)](https://github.com/elchininet/get-promisable-result/actions/workflows/deploy.yaml)\n[![Tests](https://github.com/elchininet/get-promisable-result/actions/workflows/tests.yaml/badge.svg)](https://github.com/elchininet/get-promisable-result/actions/workflows/tests.yaml)\n[![Coverage Status](https://coveralls.io/repos/github/elchininet/get-promisable-result/badge.svg?branch=master)](https://coveralls.io/github/elchininet/get-promisable-result?branch=master)\n[![npm version](https://badge.fury.io/js/get-promisable-result.svg)](https://badge.fury.io/js/get-promisable-result)\n\n## Install\n\n#### npm\n\n```bash\nnpm install get-promisable-result\n```\n\n#### yarn\n\n```bash\nyarn add get-promisable-result\n```\n\n#### PNPM\n\n```bash\npnpm add get-promisable-result\n```\n\n## API\n\n```typescript\ngetPromisableResult(\n  getResultFunction: () =\u003e T,\n  checkResult: (result: T) =\u003e boolean,\n  options: PromisableOptions = {}\n): Promise\u003cT\u003e\n```\n\n`getResultFunction` should be a function that returns something. This something is what you expect when the promise gets resolved.\n\n`checkResult` is a function that will have as a parameter the result of the `getResultFunction` and it should return a `boolean` to validate that the result is OK. If this function returns `false`, the `getResultFunction` will be executed a limited number of times (consult the [options](#options) section) until its result pass the check or until it reached the `retries` (consult the [options](#options) section).\n\n### Options\n\n| Parameter      | Type          | Default | Description                                                         |\n| -------------- | ------------- | ------- | ------------------------------------------------------------------- |\n| retries        | number        | 10      | number of retries that will be performed before the promise rejects |\n| delay          | number        | 10      | delay between the retries                                           |\n| shouldReject   | boolean       | true    | indicates if the promise should be rejected when the number of retries reached the limit. If this parameter is set to `false` and the number of retries is reached the Promise will be resolved with the last value returned by `getResultFunction` |\n| rejectMessage  | string        | \\*\\*    | custom error message. It can contain the substring `{{ retries }}` and it will be replaced with the number of `retries` |\n\n\u003e\\*\\* The default `rejectMessage` will be `Could not get the result after {{ retries }} retries`\n\n## Example\n\nQuerying a DOM element that is rendered asynchronously with a custom `retries`, `delay` and `rejectMessage`\n\n```typescript\ngetPromisableResult(\n  () =\u003e document.getElementById('my-element'),\n  (element) =\u003e element !== null,\n  {\n    retries: 50,\n    delay: 100,\n    rejectMessage: 'My element could not be retrieved after {{ restries }} retries'\n  }\n)\n  .then((element) =\u003e {\n    // Do something with the element\n  })\n  .catch((error) =\u003e {\n    // Do something if the promise is rejected\n    // My element could not be retrieved after 50 retries\n  });\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felchininet%2Fget-promisable-result","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felchininet%2Fget-promisable-result","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felchininet%2Fget-promisable-result/lists"}