parallel

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package parallel provides generic parallel processing utilities for file and data processing workloads.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateWorkers

func CalculateWorkers(numItems int, taskType TaskType) int

CalculateWorkers determines the optimal number of workers based on the number of items to process and the type of workload.

func Collect

func Collect[T any, R any](items []T, fn func(item T) (R, bool)) []R

Collect is a convenience function that processes items and collects results into a slice using a simple transform function.

func Process

func Process[T any, R any](items []T, fn ProcessFunc[T, *R]) []*R

Process executes the given function on each item in parallel using a worker pool. It returns all non-nil results. The order of results is not guaranteed.

func ProcessWithErrors

func ProcessWithErrors[T any, R any](items []T, fn ProcessWithErrorFunc[T, R]) []*R

ProcessWithErrors executes the given function on each item in parallel. Items that return errors are skipped. Returns all successful results.

Types

type ProcessFunc

type ProcessFunc[T any, R any] func(item T) R

ProcessFunc is a function that processes an item and returns a result. It should handle its own errors internally and return nil for failed items.

type ProcessWithErrorFunc

type ProcessWithErrorFunc[T any, R any] func(item T) (*R, error)

ProcessWithError is similar to Process but allows the processing function to return an error. Items that error are skipped in the results.

type TaskType

type TaskType string

TaskType represents the type of processing workload

const (
	// CPUBound tasks are limited by CPU processing power
	CPUBound TaskType = "cpu-bound"
	// IOBound tasks are limited by I/O operations (network, disk)
	IOBound TaskType = "io-bound"
	// FileProcessing tasks involve mixed I/O and CPU work
	FileProcessing TaskType = "file-processing"
)

Jump to

Keyboard shortcuts

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