xsync

package
v0.27.6 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package xsync provides synchronization utilities. It is an extension to the standard sync package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Future

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

Future is a container for a value that may not yet be available.

func (*Future[T]) Load

func (a *Future[T]) Load() (T, bool)

Load returns the value stored in the Future, if it is ready.

func (*Future[T]) Ready

func (a *Future[T]) Ready() <-chan struct{}

Ready returns a channel that is closed when the value becomes available.

func (*Future[T]) Store

func (a *Future[T]) Store(v T) bool

Store sets the value of the Future.

It returns false if the value was already set.

func (*Future[T]) Wait

func (a *Future[T]) Wait() T

Wait blocks until the value becomes available.

func (*Future[T]) WaitContext added in v0.25.0

func (a *Future[T]) WaitContext(ctx context.Context) (T, error)

WaitContext blocks until the value becomes available or the context is canceled.

type Latch added in v0.20.1

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

Latch is a synchronization primitive that allows multiple goroutines to wait until the latch is set. Latches cannot be reset.

func (*Latch) Chan added in v0.20.1

func (l *Latch) Chan() <-chan struct{}

Chan returns a channel that is closed when the latch is set.

func (*Latch) IsSet added in v0.20.1

func (l *Latch) IsSet() bool

IsSet reports whether the latch has been set.

func (*Latch) Set added in v0.20.1

func (l *Latch) Set() bool

Set unblocks any goroutines that are waiting on the latch.

It returns true if the latch was set by this call, or false if it was already set.

func (*Latch) Wait added in v0.20.1

func (l *Latch) Wait()

Wait blocks until the latch is set.

func (*Latch) WaitContext added in v0.25.0

func (l *Latch) WaitContext(ctx context.Context) error

WaitContext blocks until the latch is set or ctx is canceled.

type Observable added in v0.20.1

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

Observable is an atomic value that can be observed for changes.

func (*Observable[T]) Load added in v0.20.1

func (o *Observable[T]) Load() (T, <-chan struct{})

Load returns the current value and a channel that is closed when that is replaced by a subsequent call to Store.

func (*Observable[T]) Store added in v0.20.1

func (o *Observable[T]) Store(v T)

Store updates the value.

type Signal added in v0.27.6

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

Signal is a synchronization primitive that allows one goroutine to notify another that some event has occurred.

A signal can be notified repeatedly. Each notification unblocks at most one waiting goroutine and is consumed by it. Notifications that occur while another is already pending are coalesced into one.

func (*Signal) Chan added in v0.27.6

func (s *Signal) Chan() <-chan struct{}

Chan returns a channel that unblocks when the signal is notified.

Receiving from the channel consumes the pending notification, exactly as Signal.Wait does.

func (*Signal) Notify added in v0.27.6

func (s *Signal) Notify() bool

Notify unblocks one waiting goroutine.

If there are no waiting goroutines, the notification remains pending and a future waiting goroutine will unblock immediately.

It returns true if the notification was recorded, or false if one was already pending.

func (*Signal) Wait added in v0.27.6

func (s *Signal) Wait()

Wait blocks until the signal is notified.

It unblocks immediately if a notification is pending, and consumes it.

func (*Signal) WaitContext added in v0.27.6

func (s *Signal) WaitContext(ctx context.Context) error

WaitContext blocks until the signal is notified or ctx is canceled.

It unblocks immediately if a notification is pending, and consumes it.

type SucceedOnce

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

SucceedOnce is a sync.Once variant that allows for the operation to fail.

func (*SucceedOnce) Do

func (o *SucceedOnce) Do(
	ctx context.Context,
	fn func(ctx context.Context) error,
) error

Do executes the fn if and only if it has not been called successfully before.

Jump to

Keyboard shortcuts

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