Documentation
¶
Index ¶
- Constants
- func Collect[From, To any](ctx *context.Context, executorName string, iterator iter.Seq[From], ...) error
- func Collect2[From1, From2, To any](ctx *context.Context, executorName string, iterator iter.Seq2[From1, From2], ...) error
- func CollectMap[From comparable, To any](ctx *context.Context, executorName string, values iter.Seq[From], ...) error
- func CollectSlice[From, To any](ctx *context.Context, executorName string, values iter.Seq[From], ...) error
- func HasContextExecutor(ctx context.Context, name string) bool
- func ParallelWriter(ctx context.Context, executorName string, writers ...io.Writer) io.Writer
- func SetContextExecutor(ctx context.Context, name string, executor Executor) context.Context
- func ToIndexSeq[T any](values []T) iter.Seq2[int, T]
- func ToSeq[T any](values []T) iter.Seq[T]
- func ToSeq2[K comparable, V any](values map[K]V) iter.Seq2[K, V]
- func ToSlice[T any](values iter.Seq[T]) (everything []T)
- type Appender
- type ChildExecutor
- type Collection
- type Executor
- type Iterable
- type List
- func (s *List[T]) Append(value T)
- func (s *List[T]) Clear()
- func (s *List[T]) Contains(value T) bool
- func (s *List[T]) Dequeue() (value T, ok bool)
- func (s *List[T]) Enqueue(value T)
- func (s *List[T]) Len() int
- func (s *List[T]) Peek() (value T, ok bool)
- func (s *List[T]) Pop() (value T, ok bool)
- func (s *List[T]) Push(value T)
- func (s *List[T]) Remove(value T)
- func (s *List[T]) RemoveAll(values iter.Seq[T])
- func (s *List[T]) Seq(fn func(value T) bool)
- func (s *List[T]) Update(updater func(values []T) []T)
- func (s *List[T]) Values() []T
- type Lockable
- type Locking
- type PanicError
- type Provider
- type Queue
- type Stack
- type UnlockFunc
Constants ¶
const ExecutorDefault = ""
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
func Collect[From, To any](ctx *context.Context, executorName string, iterator iter.Seq[From], processor func(From) (To, error), accumulator func(From, To)) error
Collect iterates over the provided iterator, executing the processor in parallel to map each incoming value to a result. The accumulator is used to apply the results, with an exclusive lock; accumulator will never execute in parallel. All errors returned from processor functions will be joined with errors.Join as the returned error. Panics are also captured as errors from processor and accumulator functions
func Collect2 ¶
func Collect2[From1, From2, To any](ctx *context.Context, executorName string, iterator iter.Seq2[From1, From2], processor func(From1, From2) (To, error), accumulator func(From1, From2, To)) error
Collect2 is a specialized Collect call which accepts an iter.Seq2 and maps to processor and accumulator taking 2 input parameters
func CollectMap ¶
func CollectMap[From comparable, To any](ctx *context.Context, executorName string, values iter.Seq[From], processor func(From) (To, error), result map[From]To) error
CollectMap is a specialized Collect call which fills a map using the incoming value as a key, mapped to the result
func CollectSlice ¶
func CollectSlice[From, To any](ctx *context.Context, executorName string, values iter.Seq[From], processor func(From) (To, error), slice *[]To) error
CollectSlice is a specialized Collect call which appends results to a slice
func HasContextExecutor ¶
HasContextExecutor returns true when the named executor is available in the context
func ParallelWriter ¶
ParallelWriter returns a writer that writes the contents of each write call in parallel to all provided writers
func SetContextExecutor ¶
SetContextExecutor returns a context with the named executor for use with GetExecutor
func ToIndexSeq ¶
ToIndexSeq converts a []T to an iter.Seq2[int,T] where the index is the first parameter
Types ¶
type Appender ¶
type Appender[T any] interface { Append(value T) }
Appender to allow values to be appended
type ChildExecutor ¶
type ChildExecutor interface {
ChildExecutor() Executor
}
ChildExecutor interface, if implemented, will cause ContextExecutor calls to replace the provided context with one containing a child executor returned from this function. This is used when it is not safe to nest Go calls
type Collection ¶
type Collection[T any] interface { Iterable[T] Appender[T] Remove(value T) Contains(value T) bool Len() int }
Collection is a generic collection of values, which can be added to, removed from, and provide a length
type Executor ¶
type Executor interface {
// Go adds a unit of work to be executed by the executor. Depending on the execution strategy this may be blocking
// or may execute the function directly
Go(func())
// Wait blocks and waits for all the executing functions to be completed before returning, or the context is cancelled.
// if more functions are added to be executed by this executor after the Wait call, these will also complete before Wait proceeds
// If the context is canceled, any queued functions will not be executed
Wait(context.Context)
}
Executor the executor interface allows for different strategies to execute units of work and wait for all units of work to be completed
func ContextExecutor ¶
ContextExecutor returns an executor in context with the given name, or a serial executor if none exists and replaces the context with one that contains a new executor which won't deadlock
func NewExecutor ¶
NewExecutor returns an Executor based on the desired concurrency:
< 0: unbounded, spawn a new goroutine for each Go call 0: serial, executes in the same thread/routine as the caller of Go > 0: a bounded executor with the maximum concurrency provided
type Iterable ¶
type Iterable[T any] interface { // Seq provides an iter.Seq compatible iterator Seq(fn func(value T) bool) }
Iterable provides a function to iterate a series of values
type List ¶
type List[T comparable] struct { Locking // contains filtered or unexported fields }
type Lockable ¶
type Lockable interface {
Lock() (unlock UnlockFunc)
RLock() (unlock UnlockFunc)
}
Lockable implementors provide the ability to RW lock a resource
type Locking ¶
type Locking struct {
// contains filtered or unexported fields
}
Locking is a utility to add Lockable behavior to a struct
func (*Locking) IsExclusiveLock ¶
func (l *Locking) IsExclusiveLock(unlockFunc UnlockFunc) (exclusive bool)
func (*Locking) Lock ¶
func (l *Locking) Lock() (unlock UnlockFunc)
func (*Locking) RLock ¶
func (l *Locking) RLock() (unlock UnlockFunc)
type PanicError ¶
func (PanicError) Error ¶
func (p PanicError) Error() string
func (PanicError) Unwrap ¶
func (p PanicError) Unwrap() error
type UnlockFunc ¶
type UnlockFunc func()