// Do executes and returns the results of the given operation.
// It automatically retries if the operation returns an error.
// To control which error should be retriable or not,
// you can wrap the error from operation with NewError function.
Do executes and returns the results of the given operation.
It automatically retries if the operation returns an error.
To control which error should be retriable or not,
you can wrap the error from operation with NewError function.
// Do executes and returns the results of the given operation . // It automatically retries if the operation returns an error . // To control which error should be retriable or not // you can wrap the error from operation with NewError function .
func (r *retry) Do(ctx context.Context, operation func() (interface{}, error)) (interface{}, error) {
	var err error
	for r.WaitNext(ctx) {
		var data interface{}
		data, err = operation()
		if err == nil {
			return data, nil
		}
		if e, ok := err.(*Error); ok {
			err = e.Err
			if !e.Retriable {
				return nil, err
			}
		}
	}
	if err != nil {
		return nil, err
	}
	return nil, ctx.Err()
}
func ( r * retry ) Do ( ctx context . Context , operation func ( ) ( interface { } , error ) ) ( interface { } , error ) { var err error for r . WaitNext ( ctx ) { var data interface { } data , err = operation ( ) if err == nil { return data , nil } if e , ok := err . ( * Error ) ; ok { err = e . Err if ! e . Retriable { return nil , err } } } if err != nil { return nil , err } return nil , ctx . Err ( ) }
Do executes and returns the results of the given operation.
Do executes and returns the results of the given operation .
// Operation was not executed due to context error.