Help us shape the future of Go! Take the 2026 Go Developer Survey

pool

package module
v0.0.0-...-b40db70 Latest Latest
Warning

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

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

README

pool

A go library for common concurrency patterns using generics.

go get github.com/aeneasr/pool

For documentation of this package see below, or read the detailed documentation on pkg.go.dev/github.com/aeneasr/pool.

Map

Map manipulates a slice and transforms it to a slice of another type concurrently. For runnable examples please check pkg.go.dev/github.com/aeneasr/pool#readme-map.

Documentation

Overview

Package pool provides pooled concurrency helpers such as a parallel Map function.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map

func Map[T any, R any](ctx context.Context, collection []T, iteratee func(context.Context, T, int) (R, error), opts ...option) ([]R, error)

Map manipulates a slice and transforms it to a slice of another type concurrently.

Example
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
result, err := Map(ctx,
	[]int{1, 2, 3, 4, 5},
	func(ctx context.Context, element int, index int) (string, error) {
		return fmt.Sprintf("element: %d", element), nil
	}, WithWorkers(4))
if err != nil {
	// ...
}
fmt.Printf("%v", result)
Output:
[element: 1 element: 2 element: 3 element: 4 element: 5]

func WithWorkers

func WithWorkers(count uint) option

WithWorkers defines how many workers will be used to process tasks at most.

Types

type Options

type Options struct {
	// Workers is the maximum amount of workers processing tasks.
	Workers int
}

Options defines how concurrent tasks should be executed.

Jump to

Keyboard shortcuts

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