gopool

package module
v0.0.0-...-2eeec98 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

README

GoPool

Simplistic goroutine pooling package to complete a set of tasks within a certain amount of concurrent goroutines + handle errors.

gopool.Pooler(gopool.PoolerParams[int]{Slice: []int{1, 2, 3, 4, 5, 6}, WorkerFn: func(item int) error {
	time.Sleep(1 * time.Second)
	println(item)
	  
	return nil
		  
}, ErrorFn: func(item int, err error, isPanic bool) {
	if isPanic {
		log.Error("Caught Panic: %s", err).Full()
	} else {
		log.Error(err.Error()).Msg()
	}
}, MaxRoutines: 2, MaxErrors: 1})

Params

  • Slice, items to complete the task upon, will act on them in an orderly fashion
  • WorkerFn, a functon taking an item of the same type (comparable) as the list elements that will perform the task on each item, can return an error which will be handled by the below function
  • ErrorFn, a function that must not panic that should log any errors or panics that are caught from the WorkerFn
  • MaxRoutines, is the max concurrent goroutines for the worker pool
  • MaxErrors, is the maximum amount of errors for an item in a WorkerFn

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pooler

func Pooler[V comparable](p PoolerParams[V])

Types

type Data

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

type PoolerParams

type PoolerParams[V comparable] struct {
	Slice                  []V
	WorkerFn               func(V) error
	ErrorFn                func(V, error, bool)
	MaxRoutines, MaxErrors int
}

Jump to

Keyboard shortcuts

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