parallel

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detachable added in v0.5.1

func Detachable(ctx context.Context, nJobs, nWorkers, nMaxDetached int, worker func(*Context, int)) error

func For

func For(ctx context.Context, nJobs, nWorkers int, worker func(int)) error

func ForEach

func ForEach[T any](ctx context.Context, a []T, nWorkers int, worker func(int, T)) error

func InitChatCompletionLimiters

func InitChatCompletionLimiters(rpm, tpm int)

func InitEmbeddingLimiters

func InitEmbeddingLimiters(rpm, tpm int)

func Parallel

func Parallel(ctx context.Context, nJobs, nWorkers int, worker func(workerId, jobId int) error) error

Parallel schedules and runs tasks in parallel. nTask is the number of tasks. nJob is the number of executors. worker is the executed function which passed a range of task Names (begin, end). The ctx argument allows callers to cancel outstanding work.

func Split

func Split[T any](a []T, n int) [][]T

Split a slice into n slices and keep the order of elements.

Types

type Context added in v0.5.1

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) Attach added in v0.5.1

func (ctx *Context) Attach()

func (*Context) Detach added in v0.5.1

func (ctx *Context) Detach()

type RateLimiter

type RateLimiter interface {
	Take(count int64) time.Duration
}
var (
	ChatCompletionBackoff                     = time.Duration(0)
	ChatCompletionRequestsLimiter RateLimiter = &Unlimited{}
	ChatCompletionTokensLimiter   RateLimiter = &Unlimited{}
	EmbeddingBackoff                          = time.Duration(0)
	EmbeddingRequestsLimiter      RateLimiter = &Unlimited{}
	EmbeddingTokensLimiter        RateLimiter = &Unlimited{}
)

type Unlimited

type Unlimited struct{}

func (*Unlimited) Take

func (n *Unlimited) Take(count int64) time.Duration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL