{"id":26605120,"url":"https://github.com/timursevimli/tekrar","last_synced_at":"2026-06-13T10:32:25.630Z","repository":{"id":241871628,"uuid":"807869661","full_name":"timursevimli/tekrar","owner":"timursevimli","description":"An abstraction for handling retry strategies, including exponential backoff and custom configurations, for operations that fail.","archived":false,"fork":false,"pushed_at":"2026-03-10T23:50:28.000Z","size":121,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-11T04:49:55.441Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timursevimli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-05-29T23:55:43.000Z","updated_at":"2026-03-10T23:50:32.000Z","dependencies_parsed_at":"2024-05-31T13:03:19.607Z","dependency_job_id":"fb71b41a-ea24-4f10-8ac5-8692b62fc532","html_url":"https://github.com/timursevimli/tekrar","commit_stats":null,"previous_names":["timursevimli/recoverify","timursevimli/retry","timursevimli/tekrar"],"tags_count":1,"template":false,"template_full_name":"timursevimli/module-temp","purl":"pkg:github/timursevimli/tekrar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timursevimli%2Ftekrar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timursevimli%2Ftekrar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timursevimli%2Ftekrar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timursevimli%2Ftekrar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timursevimli","download_url":"https://codeload.github.com/timursevimli/tekrar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timursevimli%2Ftekrar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34281700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-03-23T20:30:35.546Z","updated_at":"2026-06-13T10:32:25.590Z","avatar_url":"https://github.com/timursevimli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tekrar\n\n[![npm version](https://img.shields.io/npm/v/tekrar.svg)](https://www.npmjs.com/package/tekrar)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Node.js CI](https://github.com/timursevimli/tekrar/actions/workflows/node.js.yml/badge.svg)](https://github.com/timursevimli/tekrar/actions/workflows/node.js.yml)\n\nAn abstraction for handling retry strategies, including exponential backoff and custom configurations, for operations that fail.\n\n\u003e **Note:** \"Tekrar\" means \"repeat\" or \"retry\" in Turkish, reflecting the module's purpose.\n\n## Features\n\n- Simple and lightweight retry mechanism\n- Support for both synchronous and asynchronous functions\n- Configurable retry count and delay\n- Custom error handling and recovery functions\n- TypeScript support\n\n## Installation\n\n```bash\nnpm install tekrar\n```\n\n## Usage\n\n### Basic Usage\n\n```javascript\nconst tekrar = require('tekrar');\n\n// Wrap a function that might fail\nconst fetchData = tekrar(\n  async () =\u003e {\n    const response = await fetch('https://api.example.com/data');\n    if (!response.ok) throw new Error('API request failed');\n    return response.json();\n  },\n  { count: 3, delay: 1000 },\n);\n\n// Use the wrapped function\ntry {\n  const data = await fetchData();\n  console.log('Data:', data);\n} catch (error) {\n  console.error('All retries failed:', error);\n}\n```\n\n### With Recovery Function\n\n```javascript\nconst tekrar = require('tekrar');\n\nconst sendEmail = tekrar(\n  async (recipient, content) =\u003e {\n    // Email sending logic that might fail\n    return emailService.send(recipient, content);\n  },\n  {\n    count: 3,\n    delay: 2000,\n    recovery: async (recipient, content) =\u003e {\n      // Log the failure or perform alternative action\n      console.log(`Failed to send email to ${recipient}, retrying...`);\n      // You could also modify the content or recipient before the next retry\n    },\n    onError: (error) =\u003e {\n      // Log each error\n      console.error('Email sending error:', error.message);\n    },\n  },\n);\n\n// Use the wrapped function\ntry {\n  await sendEmail('user@example.com', 'Hello, world!');\n  console.log('Email sent successfully');\n} catch (error) {\n  console.error('Failed to send email after multiple attempts');\n}\n```\n\n## API\n\n### tekrar(task, options)\n\nCreates a wrapped function that will retry the given task according to the specified options.\n\n#### Parameters\n\n- `task` (Function): The function to retry. Can be synchronous or asynchronous.\n- `options` (Object, optional): Configuration options for retry behavior.\n  - `count` (Number, default: 1): Maximum number of retry attempts.\n  - `delay` (Number, default: 0): Delay in milliseconds between retry attempts.\n  - `recovery` (Function, default: () =\u003e Promise.resolve()): Function called after each failed attempt, before the next retry. Receives the same arguments as the task.\n  - `onError` (Function, default: () =\u003e {}): Function called with each error that occurs. Useful for logging or monitoring.\n\n#### Returns\n\nA wrapped function that accepts the same arguments as the original task and returns a Promise.\n\n#### Errors\n\nIf all retry attempts fail, the function throws an `AggregateError` containing all errors that occurred during the retry attempts.\n\n## Examples\n\n### Retry with Exponential Backoff\n\n```javascript\nconst tekrar = require('tekrar');\n\n// Helper function to implement exponential backoff\nconst withExponentialBackoff = (fn, maxRetries = 5) =\u003e {\n  let retries = 0;\n\n  const execute = tekrar(fn, {\n    count: maxRetries,\n    delay: 0, // We'll handle the delay in the recovery function\n    recovery: async (...args) =\u003e {\n      const delay = Math.pow(2, retries) * 100; // Exponential backoff\n      console.log(`Retrying in ${delay}ms...`);\n      await new Promise((resolve) =\u003e setTimeout(resolve, delay));\n      retries++;\n    },\n  });\n\n  return execute;\n};\n\n// Usage\nconst fetchWithRetry = withExponentialBackoff(async (url) =\u003e {\n  const response = await fetch(url);\n  if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);\n  return response.json();\n});\n\n// Use the function\nfetchWithRetry('https://api.example.com/data')\n  .then((data) =\u003e console.log('Success:', data))\n  .catch((error) =\u003e console.error('All retries failed:', error));\n```\n\n## License\n\nMIT\n\n## Author\n\nTimur Sevimli \u003csvmlitimur@gmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimursevimli%2Ftekrar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimursevimli%2Ftekrar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimursevimli%2Ftekrar/lists"}