synctx

package
v0.4.26 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package synctx implements helpers for the context package on top of the sync package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WaitGroup

type WaitGroup struct {
	sync.WaitGroup
}

WaitGroup extended with Finish func

func (*WaitGroup) Finish

func (wg *WaitGroup) Finish() <-chan struct{}

Finish allows to be used easily with go contexts

type WorkFunc

type WorkFunc func(ctx context.Context) error

WorkFunc a function that receives an context and optionally returns an error. Returning an error will cancel all other worker functions

type WorkQueue

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

WorkQueue is a work queue implementation that respects cancellation using contexts

func NewWorkQueue

func NewWorkQueue(ctx context.Context) *WorkQueue

NewWorkQueue creates a new WorkQueue that respects the passed context for cancellation

func (*WorkQueue) Add

func (queue *WorkQueue) Add(description string, fn WorkFunc)

Add add work to the work queue. The passed description will be used for the error message, if any. The function will be immediately executed.

func (*WorkQueue) Err

func (queue *WorkQueue) Err() error

Err returns the error if one of the work queue items failed

func (*WorkQueue) Wait

func (queue *WorkQueue) Wait()

Wait waits until all worker functions are done, one worker is failing or the context is canceled

Jump to

Keyboard shortcuts

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