code: func Retry(ctx context.Context, f Factory, fn func() error, callback Callback) (err error) {
  	var it Iterator
  	if f != nil {
  		it = f()
  	}
  
  	timer := clock.NewTimer(ctx)
  	defer timer.Stop()
  
  	for {
  		// If we've been cancelled, don't call fn.
  		if err := ctx.Err(); err != nil {
  			return err
  		}
  
  		// Execute the function.
  		err = fn()
  		if err == nil || it == nil {
  			return
  		}
  
  		// If we've been cancelled, don't call Next or callback.
  		if ctx.Err() != nil {
  			return err
  		}
  
  		delay := it.Next(ctx, err)
  		if delay == Stop {
  			return
  		}
  
  		// Notify our observer that we are retrying.
  		if callback != nil {
  			callback(err, delay)
  		}
  
  		if delay > 0 {
  			timer.Reset(delay)
  			if tr := <-timer.GetC(); tr.Incomplete() {
  				// Context was canceled.
  				return tr.Err
  			}
  		}
  	}
  }
docs: // Retry executes a function 'fn'. If the function returns an error, it will
  // be re-executed according to a retry plan.
  //
  // If a Factory is supplied, it will be called to generate a single retry
  // Iterator for this Retry round. If nil, Retry will execute the target function
  // exactly once regardless of return value.
  //
  // If the supplied context is canceled, retry will stop executing. Retry will
  // not execute the supplied function at all if the context is canceled when
  // Retry is invoked.
  //
  // If 'callback' is not nil, it will be invoked if an error occurs (prior to
  // sleeping).