code: func (client *clientImpl) finalizeUpload(ctx context.Context, opID string, timeout time.Duration) error {
  	ctx, cancel := clock.WithTimeout(ctx, timeout)
  	defer cancel()
  
  	sleep := time.Second
  	for {
  		select {
  		case <-ctx.Done():
  			return ErrFinalizationTimeout
  		default:
  		}
  
  		op, err := client.cas.FinishUpload(ctx, &api.FinishUploadRequest{
  			UploadOperationId: opID,
  		})
  		switch {
  		case err == context.DeadlineExceeded:
  			continue // this may be short RPC deadline, try again
  		case err != nil:
  			return humanErr(err)
  		case op.Status == api.UploadStatus_PUBLISHED:
  			return nil // verified!
  		case op.Status == api.UploadStatus_ERRORED:
  			return errors.New(op.ErrorMessage) // fatal verification error
  		case op.Status == api.UploadStatus_UPLOADING || op.Status == api.UploadStatus_VERIFYING:
  			logging.Infof(ctx, "cipd: uploading - verifying")
  			if clock.Sleep(clock.Tag(ctx, "cipd-sleeping"), sleep).Incomplete() {
  				return ErrFinalizationTimeout
  			}
  			if sleep < 10*time.Second {
  				sleep += 500 * time.Millisecond
  			}
  		default:
  			return fmt.Errorf("unrecognized upload operation status %s", op.Status)
  		}
  	}
  }
docs: // finalizeUpload repeatedly calls FinishUpload RPC until server reports that
  // the uploaded file has been verified.