syncs

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package syncs provides synchronization primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

Group is a sync.WaitGroup with a Go method.

func (*Group) Go

func (g *Group) Go(f func())

func (*Group) Running

func (g *Group) Running() int64

Running returns the number of goroutines that are currently running.

If a call to [Running] returns zero, and a call to [Wait] is made without any calls to [Go], then [Wait] will return immediately. This is true even if a goroutine is started and finishes between the two calls.

It is possible for [Running] to return non-zero and for [Wait] to return immediately. This can happen if the all running goroutines finish between the two calls.

func (*Group) Wait

func (g *Group) Wait()

type Line

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

Line is an ordered sequence of tickets waiting for their turn to proceed.

To get a ticket use Line.Take. To signal that a ticket is done use Ticket.Done. To wait your turn use Ticket.Ready.

A Line is not safe for concurrent use.

func (*Line) Take

func (q *Line) Take() *Ticket

type RelayReader

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

RelayReader implements an io.WriterTo that yields the passed writer to its [WriteTo] method each io.WriteCloser taken from [Take], in the order they are taken. Each io.WriteCloser blocks until the previous one is closed, or a call to RelayReader.CloseWithError is made.

The zero value is invalid. Use [NewWriteToLine] to get a valid RelayReader.

It is not safe for concurrent use.

func NewRelayReader

func NewRelayReader() *RelayReader

func (*RelayReader) Close

func (q *RelayReader) Close() error

Close closes the line. Any writer waiting for its turn will be unblocked with an io.ErrClosedPipe error.

It never returns an error.

func (*RelayReader) CloseWithError

func (q *RelayReader) CloseWithError(err error) error

CloseWithError terminates the line, unblocking any writer waiting for its turn with the error, or io.EOF if err is nil. It is safe to call [CloseWithError] multiple times and across multiple goroutines.

If the line is already closed, [CloseWithError] is a no-op.

It never returns an error.

func (*RelayReader) Read

func (q *RelayReader) Read(p []byte) (int, error)

func (*RelayReader) Take

func (q *RelayReader) Take() io.WriteCloser

Take returns a writer that will be passed to the next writer in line.

It is not safe for use across multiple goroutines.

func (*RelayReader) WriteTo

func (q *RelayReader) WriteTo(dst io.Writer) (int64, error)

WriteTo yields the writer w to the first writer in line and blocks until the first call to [Close].

It is safe to call [Take] concurrently with [WriteTo].

type Ticket

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

Ticket represents a ticket in a sequence of tickets. The zero value is invalid. Use Line.Take to get a valid ticket.

A Ticket is not safe for concurrent use.

func (*Ticket) Done

func (t *Ticket) Done()

Done signals that this ticket is done and that the next ticket in line can proceed.

The first call to [Done] unblocks the ticket after it, if any. Subsequent calls are no-ops.

func (*Ticket) Ready

func (t *Ticket) Ready() chan struct{}

Ready returns a channel that is closed when the ticket before this one is done.

It is incorrect to wait on Ready after the ticket is done.

Jump to

Keyboard shortcuts

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