parcour

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

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

Go to latest
Published: Jul 10, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

README

Parcour

Parcour is a Go module with goal of making parallelism and concurrency patterns easy.

The name is a mashup of parallelism and concurrency: parallelism concurrency, and the original/french spelling of parkour.

JobGroup for Structured Concurrency

The jobgroup.JobGroup type is similar to a nursery as described in notes on structured concurrency.

From a Go perspective, it is meant to be passed around instead of a context, and functions use the Go method instead of the go keyword.
This expands user driven cancellation and timeouts, benefits of a context, to also allow user driven concurrency limits, and ensuring goroutines have an explicit scope/lifetime.

Zync

The zync module exposes basic synchronization primitives based on their counterparts from the Go standard sync module that are less error prone and use generics.
See each type's documentation for details.

Atomix

The zync/atomix module exposes wrappers for sync/atomic.

Stability

In accordance with semantic versioning, no stability guarantees are made for 0.x releases.
Patch releases will try to keep things compatible as much as possible, but break things if required to fix bugs.

Documentation

Overview

Package parcour tries to make parallelism and concurrency patterns easy.

Index

Constants

View Source
const Unbuffered = 0

Unbuffered can be used with `NewProducersWithBuffer` to obtain an unbuffered `Producers`.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer[T any] func(context.Context, <-chan T) error

Consumer is a function that consumes a series of `T`.

type ConsumersError

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

ConsumersError holds any errors returned by consumer goroutines.

func (*ConsumersError) Error

func (e *ConsumersError) Error() string

func (*ConsumersError) Unwrap

func (e *ConsumersError) Unwrap() error

type Producer

type Producer[T any] func(context.Context, chan<- T) error

Producer is a function that produces a series of `T`.

type Producers

type Producers[T any] struct {
	// contains filtered or unexported fields
}

Producers implements a multiple producer, multiple consumer pattern.

Producers create a series of items that the consumers... consume!

func NewProducersWithBuffer

func NewProducersWithBuffer[T any](producersGrp, consumersGrp jobgroup.JobGroup, bufferCap int) *Producers[T]

NewProducersWithBuffer returns a new `Producers` with the given buffer capacity.

The buffer capacity configures backpressure. It is the maximum number of items produced without a consumer receiving them. Once that limit is reached, producers will block on send, waiting for a consumer to receive.

This function panics if `bufferCap` is negative.

func NewUnbufferedProducers

func NewUnbufferedProducers[T any](producersGrp, consumersGrp jobgroup.JobGroup) *Producers[T]

NewUnbufferedProducers returns a new `Producers`.

The producers are unbuffered, meaning they will block after producing each item until a consumer receives it.

This function is equivalent to `NewProducersWithBuffer(parentGroup, Unbuffered)`.

func (*Producers[T]) BufferCap

func (p *Producers[T]) BufferCap() int

BufferCap returns the receiver's buffer capacity.

The result is undefined if the receiver's `Wait` or `Close` methods were called, though it is guaranteed the function will not panic in that case.

func (*Producers[T]) Close

func (p *Producers[T]) Close()

Close waits for the producers, closes the items channel, and then waits for consumers.

func (*Producers[T]) GoConsume

func (p *Producers[T]) GoConsume(consumer Consumer[T])

GoConsume starts a new consumer job.

func (*Producers[T]) GoProduce

func (p *Producers[T]) GoProduce(producer Producer[T])

GoProduce starts a new producer job.

func (*Producers[T]) Wait

func (p *Producers[T]) Wait() error

Wait blocks the current goroutine until all producer and consumer jobs to finish.

type ProducersError

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

ProducersError holds any errors returned by producer goroutines.

func (*ProducersError) Error

func (e *ProducersError) Error() string

func (*ProducersError) Unwrap

func (e *ProducersError) Unwrap() error

Directories

Path Synopsis
Package jobgroup provides building blocks for structured concurrency, and composable concurrency patterns.
Package jobgroup provides building blocks for structured concurrency, and composable concurrency patterns.
Package zync provides generic and safer wrappers for types from the standard sync module.
Package zync provides generic and safer wrappers for types from the standard sync module.
atomix
Package atomix provides generic and safer wrappers for types from the standard atomic module.
Package atomix provides generic and safer wrappers for types from the standard atomic module.

Jump to

Keyboard shortcuts

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