{"id":19230301,"url":"https://github.com/mrloop/ember-retry","last_synced_at":"2025-04-21T03:30:51.433Z","repository":{"id":46934118,"uuid":"54392617","full_name":"mrloop/ember-retry","owner":"mrloop","description":"Retry function / promise with configurable backoff which defaults to exponential","archived":false,"fork":false,"pushed_at":"2021-09-21T05:01:07.000Z","size":3054,"stargazers_count":7,"open_issues_count":2,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-01-04T17:46:11.481Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/mrloop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-21T13:48:58.000Z","updated_at":"2021-06-17T18:18:11.000Z","dependencies_parsed_at":"2022-09-26T18:50:50.231Z","dependency_job_id":null,"html_url":"https://github.com/mrloop/ember-retry","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrloop%2Fember-retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrloop%2Fember-retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrloop%2Fember-retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrloop%2Fember-retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrloop","download_url":"https://codeload.github.com/mrloop/ember-retry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223848259,"owners_count":17213597,"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-09T15:37:41.882Z","updated_at":"2024-11-09T15:37:42.385Z","avatar_url":"https://github.com/mrloop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![CI](https://github.com/mrloop/ember-retry/workflows/CI/badge.svg)\n\nember-retry\n==============================================================================\n\n[Ember](https://ember-cli.com) addon for exponetial backoff retries of a function.\n\nCompatibility\n------------------------------------------------------------------------------\n\n* Ember.js v3.16 or above\n* Ember CLI v2.13 or above\n* Node.js v10 or above\n\n\nInstallation\n------------------------------------------------------------------------------\n\n```\nember install ember-retry\n```\n\n\nUsage\n------------------------------------------------------------------------------\n\n```javascript\nimport retry from 'ember-retry/retry'\n\nretry((resolve, reject) =\u003e { //retry\n  let ws = new WebSocket('ws://myflakyhost.com');\n  ws.onopen = () =\u003e resolve(ws);\n  ws.onerror = (error) =\u003e reject(error);\n}).then((websocket) =\u003e {\n  //do something with websocket\n});\n\nretry(() =\u003e {\n  return this.store.find('user', 353232); //retry if promise fails with error\n}).then((user) =\u003e {\n  //do something with user\n});\n```\n\nBy default will retry 5 times after 0.5s, 1s, 2s, 4s, 8s.\nThe number of retries, initial delay before retries and the function used to calculate retry delay can all be configured.\n\n```javascript\nretry(() =\u003e {\n  return this.store.find('user', 353232);\n}, 3, 1000) //retry 3 times at 1000ms, 2000ms, 4000ms\n```\n\n```javascript\nretry(() =\u003e {\n  return this.store.find('user', 353232);\n}, 5, (retryIndex) =\u003e { return retryIndex+1*40; }); //retry 5 times at 40ms, 80ms, 120ms, 160ms, 200ms\n```\n\nWill retry if return value `isNone`\n\n```javascript\nretry(() =\u003e {\n  if (Math.random() \u003e 0.5) {\n    return 'What am I trying to do?';\n  }\n}).then((str) =\u003e {\n  // str is 'What am I trying to do?' if successful;\n})\n```\n\nCan pass an anonymous function to retry conditionally\nIn this case if the response.status is not 401\n```javascript\nretry(() =\u003e {\n  return this.store.find('user', 353232);\n}, 5, 1000, (response) =\u003e { return (response.status !== 401) });\n```\n\n\nContributing\n------------------------------------------------------------------------------\n\nSee the [Contributing](CONTRIBUTING.md) guide for details.\n\n\nAlternatives\n------------------------------------------------------------------------------\n\n\n_Why don't you use existing alternative instead e.g. ember-backoff?_\n\nI wanted a cleaner way to retry a function where a promise wasn't returned.\n\n* [ember-backoff](https://github.com/GavinJoyce/ember-backoff)\n* [ember-concurrency](https://github.com/machty/ember-concurrency) like [this](http://blog.mrloop.com/javascript/ember/2016/04/12/retrying-functions-with-ember-concurrency.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrloop%2Fember-retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrloop%2Fember-retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrloop%2Fember-retry/lists"}