ofetch icon indicating copy to clipboard operation
ofetch copied to clipboard

feat: support callback in retryDelay

Open escral opened this issue 1 year ago โ€ข 1 comments

๐Ÿ”— Linked issue

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • [ ] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [ ] ๐Ÿ‘Œ Enhancement (improving an existing functionality like performance)
  • [x] โœจ New feature (a non-breaking change that adds functionality)
  • [ ] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

Calculate retry delay based on context. Opens possibility to make retries with incremental delay. For example:

{
  retry: 3,
  retryDelay: (context) => {
      const attempt = context.options.retryAttempt = (context.options.retryAttempt || 0) + 1;
      return 300 * (Math.pow(3, attempt - 1))
  },
}

๐Ÿ“ Checklist

  • [ ] I have linked an issue or discussion.
  • [ ] I have updated the documentation accordingly.

escral avatar Mar 05 '24 17:03 escral

Though I don't like having this context.options "hack". Would be nice to have shared context between retries.

escral avatar Mar 05 '24 18:03 escral