parallel

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchParallel

func BatchParallel(nJobs, nWorkers, batchSize int, worker func(workerId, beginJobId, endJobId int) error) error

BatchParallel run parallel jobs in batches to reduce the cost of context switch.

func Detachable added in v0.5.1

func Detachable(nJobs, nWorkers, nMaxDetached int, worker func(*Context, int))

func For

func For(nJobs, nWorkers int, worker func(int))

func ForEach

func ForEach[T any](a []T, nWorkers int, worker func(int, T))

func InitChatCompletionLimiters

func InitChatCompletionLimiters(rpm, tpm int)

func InitEmbeddingLimiters

func InitEmbeddingLimiters(rpm, tpm int)

func Parallel

func Parallel(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).

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 ConcurrentPool

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

func NewConcurrentPool

func NewConcurrentPool(size int) *ConcurrentPool

func (*ConcurrentPool) Run

func (p *ConcurrentPool) Run(runner func())

func (*ConcurrentPool) Wait

func (p *ConcurrentPool) Wait()

type ConditionChannel

type ConditionChannel struct {
	C chan struct{} // output channel
	// contains filtered or unexported fields
}

func NewConditionChannel

func NewConditionChannel() *ConditionChannel

func (*ConditionChannel) Close

func (c *ConditionChannel) Close()

func (*ConditionChannel) Signal

func (c *ConditionChannel) Signal()

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 Pool

type Pool interface {
	Run(runner func())
	Wait()
}

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 SequentialPool

type SequentialPool struct{}

func NewSequentialPool

func NewSequentialPool() *SequentialPool

func (*SequentialPool) Run

func (p *SequentialPool) Run(runner func())

func (*SequentialPool) Wait

func (p *SequentialPool) Wait()

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