parallel

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package parallel provides concurrency utilities for parallel data processing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParallelForEach

func ParallelForEach[T any](data []T, fn func(T), workers int)

ParallelForEach applies a function to each element in parallel (no return value).

func ParallelMap

func ParallelMap[T, R any](data []T, fn func(T) R, workers int) []R

ParallelMap applies a function to each element in parallel and returns results.

func ParallelReduce

func ParallelReduce[T, R any](data []T, fn func(T, R) R, initial R, combiner func(R, R) R, workers int) R

ParallelReduce reduces data using a function in parallel.

Types

type Pool

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

Pool represents a worker pool for parallel task execution.

func NewPool

func NewPool(workers int) *Pool

NewPool creates a new worker pool with the specified number of workers. If workers <= 0, it defaults to runtime.NumCPU().

func (*Pool) Close

func (p *Pool) Close()

Close closes the pool and stops all workers.

func (*Pool) Submit

func (p *Pool) Submit(fn func())

Submit submits a task to the pool for execution.

func (*Pool) Wait

func (p *Pool) Wait()

Wait waits for all submitted tasks to complete.

Jump to

Keyboard shortcuts

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