You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: retry.go
    path of file: ./repos/go-zero/core/fx
    
    the code of the file until where you have to start completion: package fx

import (
	"context"
	"errors"
	"time"

	"github.com/zeromicro/go-zero/core/errorx"
)

const defaultRetryTimes = 3

type (
	// RetryOption defines the method to customi
    
func retry(ctx context.Context, fn func(errChan chan error, retryCount int), opts ...RetryOption) error {
	options := newRetryOptions()
	for _, opt := range opts {
		opt(options)
	}

	var berr errorx.BatchError
	var cancelFunc context.CancelFunc
	if options.timeout > 0 {
		ctx, cancelFunc = context.WithTimeout(ctx, options.timeout)
		defer cancelFunc()
	}

	errChan := make(chan error, 1)
	for i := 0; i < options.times; i++ {
		go fn(errChan, i)

		select {
		case err := <-errChan:
			if err != nil {
				for _, ignoreErr := range options.ignoreErrors {
					if errors.Is(err, ignoreErr) {
						return nil
					}
				}
				berr.Add(err)
			} else {
				return nil
			}
		case <-ctx.Done():
			berr.Add(ctx.Err())
			return berr.Err()
		}

		if options.interval > 0 {
			select {
			case <-ctx.Done():
				berr.Add(ctx.Err())
				return berr.Err()
			case <-time.After(options.interval):
			}
		}
	}

	return berr.Err()
}