You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GoRetry currently provides excellent retry functionality for operations that return only an error (func() error), but many real-world scenarios require retrying operations that return values alongside potential errors (func() (T, error)).
Use Cases:
Database queries that return data
API calls that fetch resources
File operations that read content
Any operation where the return value is needed on success
Current Workaround:
Users must capture values outside the retry function using closures, which is verbose and not type-safe:
varresultSomeTypeerr:=goretry.IfNeeded(func() error {
varerrerrorresult, err=someOperation()
returnerr
})
// Use 'result' here
Proposed Solution:
Add generic versions of the core retry functions that support value-returning operations:
Ensure all existing retry policies and options work with new functions
Add comprehensive tests for type safety and error handling
Update documentation with examples
Maintain backward compatibility with existing API
Notes
This enhancement would make GoRetry more comprehensive for real-world applications while preserving the excellent design patterns already established. The naming follows the existing convention with "WithValue" suffix to clearly distinguish from error-only variants.
GoRetry currently provides excellent retry functionality for operations that return only an error (
func() error), but many real-world scenarios require retrying operations that return values alongside potential errors (func() (T, error)).Use Cases:
Current Workaround:
Users must capture values outside the retry function using closures, which is verbose and not type-safe:
Proposed Solution:
Add generic versions of the core retry functions that support value-returning operations:
Benefits:
Acceptance Criteria
IfNeededWithValue[T any](fn func() (T, error), options ...Option) (T, error)IfNeededWithPolicyAndValue[T any](policy RetryPolicy, fn func() (T, error), options ...Option) (T, error)IfNeededWithContextAndValue[T any](ctx context.Context, fn func(context.Context) (T, error), options ...Option) (T, error)IfNeededWithPolicyContextAndValue[T any](ctx context.Context, policy RetryPolicy, fn func(context.Context) (T, error), options ...Option) (T, error)Notes
This enhancement would make GoRetry more comprehensive for real-world applications while preserving the excellent design patterns already established. The naming follows the existing convention with "WithValue" suffix to clearly distinguish from error-only variants.