synctools

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

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 13 Imported by: 0

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

View Source
var (
	LoggingMutexWriter io.Writer = os.Stdout

	LogFullStack = true
)

Functions ¶

This section is empty.

Types ¶

type AbortGroup ¶

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

Alternative to sync/errgrp.ErrorGroup that cancels a context on the first error, rather than waiting for all goroutines to finish before failing.

NOTE: This is not even necessary as there is errgroup.WithContext, though this may be slightly more ergonomic. Probably not worth it.

func NewAbortGroup ¶

func NewAbortGroup(ctx context.Context) *AbortGroup

func (*AbortGroup) Go ¶

func (grp *AbortGroup) Go(fn func(ctx context.Context) error)

func (*AbortGroup) Wait ¶

func (grp *AbortGroup) Wait() (rerr error)

type AllErrGroup ¶

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

func WithContext ¶

func WithContext(ctx context.Context) (*AllErrGroup, context.Context)

func (*AllErrGroup) Errors ¶

func (g *AllErrGroup) Errors() []error

func (*AllErrGroup) Go ¶

func (g *AllErrGroup) Go(f func() error)

func (*AllErrGroup) SetLimit ¶

func (g *AllErrGroup) SetLimit(n int)

func (*AllErrGroup) TryGo ¶

func (g *AllErrGroup) TryGo(f func() error) bool

func (*AllErrGroup) Wait ¶

func (g *AllErrGroup) Wait() error

type ChanGroup ¶

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

func NewChanGroup ¶

func NewChanGroup() *ChanGroup

func (*ChanGroup) Add ¶

func (wg *ChanGroup) Add(n int)

func (*ChanGroup) Done ¶

func (wg *ChanGroup) Done()

func (*ChanGroup) Signal ¶

func (wg *ChanGroup) Signal() <-chan struct{}

func (*ChanGroup) Wait ¶

func (wg *ChanGroup) Wait()

type CondGroup ¶

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

CondGroup implements a less volatile, more general-purpose waitgroup than sync.WaitGroup.

Unlike sync.WaitGroup, new Add calls can occur before all previous waits have returned.

func NewCondGroup ¶

func NewCondGroup() *CondGroup

func (*CondGroup) Add ¶

func (wg *CondGroup) Add(n int)

func (*CondGroup) Count ¶

func (wg *CondGroup) Count() int

func (*CondGroup) Done ¶

func (wg *CondGroup) Done()

func (*CondGroup) Stop ¶

func (wg *CondGroup) Stop()

func (*CondGroup) Wait ¶

func (wg *CondGroup) Wait()

type LoggingMutex ¶

type LoggingMutex struct {
	sync.Mutex
}

func (*LoggingMutex) Lock ¶

func (l *LoggingMutex) Lock()

func (*LoggingMutex) Unlock ¶

func (l *LoggingMutex) Unlock()

type LoggingRWMutex ¶

type LoggingRWMutex struct {
	sync.RWMutex
}

func (*LoggingRWMutex) Lock ¶

func (l *LoggingRWMutex) Lock()

func (*LoggingRWMutex) RLock ¶

func (l *LoggingRWMutex) RLock()

func (*LoggingRWMutex) RUnlock ¶

func (l *LoggingRWMutex) RUnlock()

func (*LoggingRWMutex) Unlock ¶

func (l *LoggingRWMutex) Unlock()

type Mutex ¶

type Mutex = sync.Mutex

type RWLocker ¶

type RWLocker interface {
	sync.Locker

	RLocker() sync.Locker
	RLock()
	RUnlock()
}

type RWMutex ¶

type RWMutex = sync.RWMutex

type Task ¶

type Task interface {
	// Do MUST NOT panic.
	Do(ctx context.Context)
	Dropped()
}

type TaskSlot ¶

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

This is a bit of boilerplate for a very specific type of task running scenario.

  • Only one task can run at a time.
  • It may be cancelled and replaced with a task at any time.
  • If you need to wait for the task, you need to implement that yourself. This does not handle serialisation, only mutual exclusion.

--

func NewTaskSlot ¶

func NewTaskSlot() *TaskSlot

func (*TaskSlot) Next ¶

func (slot *TaskSlot) Next(task Task)

Inform the TaskSlot of the next task to run. Cancel any task currently running. The task may be nil to indicate "cancel, but there is no next task".

func (*TaskSlot) Stop ¶

func (slot *TaskSlot) Stop()

type WaitGroup ¶

type WaitGroup interface {
	Add(int)
	Done()
	Wait()
}

func NewWaitGroup ¶

func NewWaitGroup() WaitGroup

Jump to

Keyboard shortcuts

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