parallel

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 1 Imported by: 0

README

parallel

Easy concurrent/parallel work

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NMap

func NMap(n int, fn func(m int) (r any, err error), options ...Option) (resultlist []any, errorlist []error)

NMap works on every integer in the range from 0 to ... n-1 in parallel The function works with 2 arguments and an (optional) option

  • an integer n
  • a worker function with one argument (an integer) which produces a result (type any) and an error

The (optional) option gives a maximum of go-routines doing work.

The function return 2 values:

  • resultlist: a slice of any (the result of each individual worker)
  • errorlist: a slice of error (the error of each individual worker)

Options:

WithMax(int): maximum workers (the default is lower than runtime.GOMAXPROCS(-1))

Example:

resultlist, errorlist := parallel.NMap(100, func(m int) {....} (any, err), parallel.WithMax(7))

Types

type Config

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

func NewCfg

func NewCfg(opts []Option) Config

type Option

type Option func(*Config)

func WithMax

func WithMax(max int) Option

Jump to

Keyboard shortcuts

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