package backoff

import (
	
	
)

// BackOffContext is a backoff policy that stops retrying after the context
// is canceled.
type BackOffContext interface { // nolint: golint
	BackOff
	Context() context.Context
}

type backOffContext struct {
	BackOff
	ctx context.Context
}

// WithContext returns a BackOffContext with context ctx
//
// ctx must not be nil
func ( BackOff,  context.Context) BackOffContext { // nolint: golint
	if  == nil {
		panic("nil context")
	}

	if ,  := .(*backOffContext);  {
		return &backOffContext{
			BackOff: .BackOff,
			ctx:     ,
		}
	}

	return &backOffContext{
		BackOff: ,
		ctx:     ,
	}
}

func ( BackOff) context.Context {
	if ,  := .(BackOffContext);  {
		return .Context()
	}
	if ,  := .(*backOffTries);  {
		return (.delegate)
	}
	return context.Background()
}

func ( *backOffContext) () context.Context {
	return .ctx
}

func ( *backOffContext) () time.Duration {
	select {
	case <-.ctx.Done():
		return Stop
	default:
		return .BackOff.NextBackOff()
	}
}