Skip to content

Add context.Context support to more wrapper functions #151

@CybotTM

Description

@CybotTM

Summary

Currently only TimeoutWithContext wrapper supports context propagation. Other wrappers could benefit from context awareness for better integration with modern Go patterns.

Current Context Support

Wrapper Context Support Notes
TimeoutWithContext ✅ Yes Full context propagation
Timeout ❌ No Abandonment model
Recover ❌ No Could log context values
RetryWithBackoff ❌ No Could cancel on context done
CircuitBreaker ❌ No Could respect context
DelayIfStillRunning ❌ No Could timeout on context
SkipIfStillRunning ❌ No Could log context

Suggested Enhancements

RetryWithBackoffContext

func RetryWithBackoffContext(logger Logger, maxRetries int, ...) JobWrapper {
    return func(j Job) Job {
        return &retryContextJob{...}
    }
}

// Cancels retry loop when context is done
func (r *retryContextJob) RunWithContext(ctx context.Context) {
    for attempt := 1; ...; attempt++ {
        select {
        case <-ctx.Done():
            return // Stop retrying
        default:
            // Try execution
        }
    }
}

CircuitBreakerContext

Could skip execution when context is already cancelled.

Benefits

  1. Better integration with HTTP server shutdown
  2. More responsive cancellation
  3. Consistent context propagation throughout chain

Files

  • chain.go - Wrapper implementations
  • retry.go - Retry and circuit breaker

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAPI design changesenhancementNew feature or requestv1.1Deferred to v1.1 release

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions