code: func (b *Backoff) ComputeDelayForRequest(now time.Time) time.Duration {
  	b.mutex.Lock()
  	defer b.mutex.Unlock()
  
  	// Apply exponential decay to the counters
  	timeDeltaSeconds := now.Unix() - b.lastDecay
  	if timeDeltaSeconds > b.decayIntervalSeconds {
  		intervals := float64(timeDeltaSeconds) / float64(b.decayIntervalSeconds)
  		decay := float32(math.Pow(b.decayFraction, intervals))
  		b.countErrorsRequestLimit *= decay
  		b.countRequests *= decay
  		b.lastDecay = now.Unix()
  	}
  
  	// Count this request
  	b.countRequests += 1.0
  
  	// Compute the failure rate
  	errorFraction := float32(0.0)
  	if b.countRequests > 0.5 {
  		// Avoid tiny residuals & rounding errors
  		errorFraction = b.countErrorsRequestLimit / b.countRequests
  	}
  
  	// Ignore a low fraction of errors
  	// This also allows them to time-out
  	if errorFraction < 0.1 {
  		return time.Duration(0)
  	}
  
  	// Delay by the max delay multiplied by the recent error rate
  	// (i.e. we apply a linear delay function)
  	// TODO: This is pretty arbitrary
  	delay := time.Nanosecond * time.Duration(float32(b.maxDelay.Nanoseconds())*errorFraction)
  	// Round down to the nearest second for sanity
  	return time.Second * time.Duration(int(delay.Seconds()))
  }
docs: // ComputeDelayForRequest computes the delay required for a request, also
  // updates internal state to count this request