{"id":22433755,"url":"https://github.com/gavinning/retry","last_synced_at":"2025-03-27T07:46:11.374Z","repository":{"id":42857344,"uuid":"260371049","full_name":"gavinning/retry","owner":"gavinning","description":"失败自动重试","archived":false,"fork":false,"pushed_at":"2023-06-27T02:27:58.000Z","size":72,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T12:46:40.612Z","etag":null,"topics":["auto-repeat","auto-retry","repeat","repeat-request","retry","retry-request"],"latest_commit_sha":null,"homepage":null,"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/gavinning.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":"2020-05-01T03:25:45.000Z","updated_at":"2023-06-27T01:56:34.000Z","dependencies_parsed_at":"2025-02-01T12:47:33.746Z","dependency_job_id":"314c9dd0-d7d9-43f1-8198-9eb57f05101d","html_url":"https://github.com/gavinning/retry","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fretry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fretry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fretry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fretry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gavinning","download_url":"https://codeload.github.com/gavinning/retry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245806390,"owners_count":20675296,"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":["auto-repeat","auto-retry","repeat","repeat-request","retry","retry-request"],"created_at":"2024-12-05T22:15:49.444Z","updated_at":"2025-03-27T07:46:11.345Z","avatar_url":"https://github.com/gavinning.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Retry\n\n失败自动重试，可用于 http 请求重试，或其他需要重试的逻辑\n\n### Install\n\n```sh\nnpm i @4a/retry\n```\n\n### Usage\n\n```js\n// ES6\nimport Retry from '@4a/retry'\n\n// Nodejs\nconst Retry = require('@4a/retry')\n```\n\n### Example\n\n```js\nlet i = 0\n\nRetry.delay(300) // 可选调用 重试间隔300ms，默认300ms，单位ms\n  .max(10) // 可选调用 重试次数10，默认3次防止死循环\n  .when((result) =\u003e result !== 10) // 必须调用 重试条件，符合条件则重试，否则视为成功正常返回\n  .repeat(() =\u003e {\n    // 支持async函数，支持promise，返回Promise\n    i++\n    return i\n  })\n  .then((result) =\u003e {\n    console.log('result:', result)\n  })\n  .catch((err) =\u003e {\n    // 报错视为失败\n    // 最后一次重试如果依然报错，则抛出该错误\n    console.error('error:', err)\n  })\n```\n\nSimple\n\n```js\nlet i = 0\n\nRetry.when((result) =\u003e result !== 10)\n  .repeat(() =\u003e {\n    i++\n    return i\n  })\n  .then((result) =\u003e {\n    console.log('result:', result)\n  })\n  .catch((err) =\u003e {\n    console.error('error:', err)\n  })\n```\n\nAxios Request\n\n```js\nRetry.when((result) =\u003e result.data.code !== 0)\n  .repeat(() =\u003e axios(options))\n  .then((result) =\u003e {\n    console.log('result:', result)\n  })\n  .catch((err) =\u003e {\n    console.error('error:', err)\n  })\n```\n\n\u003cbr /\u003e\n\n\u003e npm test\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fretry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavinning%2Fretry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fretry/lists"}