scheduler

package
v1.0.70 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec[T any](source TaskSource[T], opts Options[T])

Exec executes tasks from the source with limited parallelism.

Types

type ChanSource

type ChanSource[T any] struct {
	// contains filtered or unexported fields
}

ChanSource wraps a channel as a TaskSource.

func FromChan

func FromChan[T any](ch <-chan T) *ChanSource[T]

FromChan creates a TaskSource from a channel.

func (*ChanSource[T]) Next

func (s *ChanSource[T]) Next(ctx context.Context) (T, bool)

Next returns the next task from the channel, or (zero, false) if the channel is closed.

type FuncSource

type FuncSource[T any] struct {
	// contains filtered or unexported fields
}

FuncSource generates tasks from a function.

func FromFunc

func FromFunc[T any](fn func(ctx context.Context) (T, bool)) *FuncSource[T]

FromFunc creates a TaskSource from a generator function. The function should return (task, true) for each task, or (zero, false) when done.

func (*FuncSource[T]) Next

func (s *FuncSource[T]) Next(ctx context.Context) (T, bool)

Next calls the generator function.

type Handler

type Handler[T any] func(context.Context, T)

Handler processes tasks from the scheduler

type IterSource

type IterSource[T any] struct {
	// contains filtered or unexported fields
}

IterSource wraps an iter.Seq as a TaskSource.

func FromIter

func FromIter[T any](seq iter.Seq[T]) *IterSource[T]

FromIter creates a TaskSource from an iterator.

func (*IterSource[T]) Next

func (s *IterSource[T]) Next(ctx context.Context) (T, bool)

Next returns the next task from the iterator.

func (*IterSource[T]) Stop

func (s *IterSource[T]) Stop()

Stop releases resources associated with the iterator.

type Options

type Options[T any] struct {
	Context     context.Context
	Handler     Handler[T]
	Parallelism int
}

Options configures a worker pool or an execution

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

Pool is a worker pool that accepts tasks at runtime

func NewPool

func NewPool[T any](opts Options[T]) *Pool[T]

NewPool creates a new worker pool with the given options

func (*Pool[T]) Close

func (p *Pool[T]) Close()

Close stops accepting new tasks and waits for all workers to finish

func (*Pool[T]) Submit

func (p *Pool[T]) Submit(task T) bool

Submit adds a task to the pool. Returns false if the context is canceled.

type SliceSource

type SliceSource[T any] struct {
	// contains filtered or unexported fields
}

SliceSource iterates over a slice as a TaskSource.

func FromSlice

func FromSlice[T any](items []T) *SliceSource[T]

FromSlice creates a TaskSource from a slice.

func FromSliceClone

func FromSliceClone[T any](items []T) *SliceSource[T]

FromSliceClone creates a TaskSource from a slice, cloning the slice.

func (*SliceSource[T]) Next

func (s *SliceSource[T]) Next(ctx context.Context) (T, bool)

Next returns the next task from the slice, or (zero, false) if the slice is exhausted.

type TaskSource

type TaskSource[T any] interface {
	Next(ctx context.Context) (T, bool)
}

TaskSource provides tasks to the scheduler

Jump to

Keyboard shortcuts

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