{"_id":"@ajimae/retry","_rev":"1-20cdd9c385a4e6da2365d211f0956c04","name":"@ajimae/retry","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@ajimae/retry","version":"0.0.1","author":{"name":"Chukwuemeka Ajima","email":"meeky.ae@gmail.com"},"license":"MIT","_id":"@ajimae/retry@0.0.1","maintainers":[{"name":"ajimae","email":"meeky.ae@gmail.com"}],"homepage":"https://github.com/ajimae/osl","bugs":{"url":"https://github.com/ajimae/osl/issues"},"dist":{"shasum":"ed050bf639d85cd9b66f6920166477eeb53d39e6","tarball":"https://registry.npmjs.org/@ajimae/retry/-/retry-0.0.1.tgz","fileCount":11,"integrity":"sha512-ignBY+jQ3iS1H/BV42Jd1FO2+dfklovtLa+BOIgh4bE+eIUX4ao/ZdjbtVfMl5ffTS91DkroeURHdVHzgRHhQg==","signatures":[{"sig":"MEUCICiMNmurx56eY4b+S3Ohw58CLshZvP0uBOuo6BwJQ/7tAiEA2mLZsVmFDc4I/TTdpv7gl7bPZm5ByhUWa2JM3hRfpJ4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":95974},"main":"dist/ajimae-retry.cjs.js","types":"./dist/ajimae-retry.cjs.d.ts","module":"dist/ajimae-retry.esm.js","browser":{"./dist/ajimae-retry.cjs.js":"./dist/ajimae-retry.browser.cjs.js","./dist/ajimae-retry.esm.js":"./dist/ajimae-retry.browser.esm.js"},"gitHead":"a837c274bde0b5ca1c3059dbccd8cef39008d27a","keyword":["retry","async-retry","backoff","efficient","simple-retry","typescript","node","express","react","react-native","browser"],"_npmUser":{"name":"ajimae","email":"meeky.ae@gmail.com"},"repository":{"url":"git+https://github.com/ajimae/osl.git","type":"git"},"_npmVersion":"8.11.0","description":"simple, easy-to-use and zero-dependency javascript async retry package.","directories":{},"_nodeVersion":"16.15.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/retry_0.0.1_1690984354042_0.9620778135040873","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"@ajimae/retry","version":"0.0.2","license":"MIT","description":"simple, easy-to-use and zero-dependency javascript async retry package.","keyword":["retry","async-retry","backoff","efficient","simple-retry","typescript","node","express","react","react-native","browser"],"homepage":"https://github.com/ajimae/osl","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/ajimae/osl.git"},"bugs":{"url":"https://github.com/ajimae/osl/issues"},"author":{"name":"Chukwuemeka Ajima","email":"meeky.ae@gmail.com"},"main":"dist/ajimae-retry.cjs.js","module":"dist/ajimae-retry.esm.js","browser":{"./dist/ajimae-retry.cjs.js":"./dist/ajimae-retry.browser.cjs.js","./dist/ajimae-retry.esm.js":"./dist/ajimae-retry.browser.esm.js"},"types":"./dist/ajimae-retry.cjs.d.ts","gitHead":"43d85dd7c3360f6651697737325bc8e109dd7e50","_id":"@ajimae/retry@0.0.2","_nodeVersion":"16.15.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-unetefAyfWgTUNuCemOtlVmrioITmqSqAMtIW5r2XCJFNo5E102JlJbeYrGMwLgqa1M/GwKEyuBMQ5FwKhkh3Q==","shasum":"1c530d251fbb88f19c30602afd6fdbd517fe9e0a","tarball":"https://registry.npmjs.org/@ajimae/retry/-/retry-0.0.2.tgz","fileCount":12,"unpackedSize":103650,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGxdYm7PQoq6a7DRBsvwpIzKhRGObautOWe3ur2QvBsjAiBkY4sWHMiZvPqKAK6/tDpZXHaOU/4c+GHfwLuUC0a4HQ=="}]},"_npmUser":{"name":"ajimae","email":"meeky.ae@gmail.com"},"directories":{},"maintainers":[{"name":"ajimae","email":"meeky.ae@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/retry_0.0.2_1727547987679_0.42044047430641474"},"_hasShrinkwrap":false}},"time":{"created":"2023-08-02T13:52:33.990Z","modified":"2024-09-28T18:26:28.100Z","0.0.1":"2023-08-02T13:52:34.179Z","0.0.2":"2024-09-28T18:26:27.913Z"},"bugs":{"url":"https://github.com/ajimae/osl/issues"},"author":{"name":"Chukwuemeka Ajima","email":"meeky.ae@gmail.com"},"license":"MIT","homepage":"https://github.com/ajimae/osl","repository":{"type":"git","url":"git+https://github.com/ajimae/osl.git"},"description":"simple, easy-to-use and zero-dependency javascript async retry package.","maintainers":[{"name":"ajimae","email":"meeky.ae@gmail.com"}],"readme":"# @ajimae/retry\n\n## Overview\nA simple, easy-to-use and zero-dependency javascript async retry package.\n\n## Getting Started\n```bash\n$ yarn add @ajimae/retry\n```\nor using npm\n```bash\n$ npm install @ajimae/retry\n```\n\n## Usage\nBasic usage example\n\n```ts\n// import the package\nimport { retry } from '@ajimae/retry';\n\n// create the retry wrapper\nasync function exec() {\n  return new Promise((resolve) => {\n    // simulate a network call that takes 1.5 seconds\n    setTimeout(() => {\n      resolve({\n        statusCode: 200,\n        message: 'success',\n        data: {\n          name: 'meeky',\n          age: 150\n        }\n      })\n    }, 1500);\n  });\n};\n\n// create a predicate function\nfunction predicate(response, retryCount) {\n  /**\n   * access the retry count using the `retryCount` param,\n   * once the condition or conditions specified in this\n   * predicate function is met or the `maxRetries` is exhausted\n   * (retryCount == maxRetries) the retry exits.\n   */\n  return (response.statusCode != 200);\n}\n\n(async function main() {\n  const result = await retry(exec, predicate, { maxRetries: 5 })\n})();\n\n```\n\n### Package API\n\n**Retry function**\n\nThe package exposes a `retry` function which is a simple function that takes in three (3) arguments and returns a generic promise.\n\n```ts\n// exposed retry function\nfunction retry<T>(\n  fn: () => Promise<T>,\n  predicate: (response: T, retryCount: number) => boolean,\n  retryPolicy?: Partial<RetryPolicy>\n): Promise<T>;\n```\n\n**The retry function arguments**\n\n**execute**\n- A function (usually an (anonymous) async function) that returns a promise-like value.\n```ts\nasync function execute(): Promise<T> {\n  return T\n}\n```\n\n**predicate**\n- A predicate (function) takes in the response (the result from the `execute` function) as the first argument, a `retryCount` as the second argument and returns a boolean.\n\n```ts\nfunction predicate(response: T, retryCount: number): boolean {\n  return true | false\n}\n```\n\n**retryPolicy**\n- An object that defines how the retry should be performed.\n\n```ts\nimport { RetryPolicy } from '@ajimae/retry'\n\nconst retryPolicy: Partial<RetryPolicy> = {\n  maxRetries: number;\n  backoff: boolean;\n  retryDelay: number;\n  maxDelay: number;\n}\n```\n**Note:**\nThe package also exposes the typescript type `RetryPolicy`\n\n```ts\nimport { retry, RetryPolicy } from '@ajimae/retry'\n```\n\n## Author\nChukwuemeka Ajima - [@ajimae](https://github.com/ajimae)\n\n## License\nThis project is licensed under the **MIT License**.\n\nSee [LICENSE](https://github.com/ajimae/osl/blob/HEAD/LICENSE) for more information.\n","readmeFilename":"README.md"}