// wait implements Wait, taking exponentialBackoff and sleeper arguments for testing. func (op *Operation) wait(ctx context.Context, resp proto.Message, bo *gax.Backoff, sl sleeper) error { for { if err := op.Poll(ctx, resp); err != nil { return err } if op.Done() { return nil } if err := sl(ctx, bo.Pause()); err != nil { return err } } }
func retry(ctx context.Context, bo gax.Backoff, f func() (stop bool, err error), sleep func(context.Context, time.Duration) error) error { var lastErr error for { stop, err := f() if stop { return err } // Remember the last "real" error from f. if err != nil && err != context.Canceled && err != context.DeadlineExceeded { lastErr = err } p := bo.Pause() if cerr := sleep(ctx, p); cerr != nil { if lastErr != nil { return fmt.Errorf("%v; last function err: %v", cerr, lastErr) } return cerr } } }