msync

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: BSD-3-Clause Imports: 1 Imported by: 0 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

msync

GoDoc CI

This repository defines a library of Go types to help in the management of concurrency.

Packages

Documentation

Overview

Package msync defines some helpful types for managing concurrency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag added in v0.1.0

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

A Flag is a level-triggered single-value buffer shared by a producer and a consumer. A producer calls Flag.Set to make a value available, and a consumer calls Flag.Ready to obtain a channel which delivers the most recently-sent value.

Setting value on the flag does not block: Once a value is set, additional values are discarded until the buffered value is consumed.

The Flag.Ready method returns a channel that delivers buffered values to the consumer. Once a value has been consumed, the buffer is empty and the producer can send another.

func NewFlag added in v0.1.0

func NewFlag[T any]() *Flag[T]

NewFlag constructs a new empty flag.

func (*Flag[T]) Ready added in v0.1.0

func (f *Flag[T]) Ready() <-chan T

Ready returns a channel that delivers a value when one is available. Once a value is received, further reads on the channel will block until the flag is Set again.

func (*Flag[T]) Set added in v0.1.0

func (f *Flag[T]) Set(v T) bool

Set buffers or discards v, and reports whether v was buffered (true) or discarded (false). Set does not block.

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

Link is a snapshot of a Value acquired by a call to its LoadLink method. Use [Linked.Get] to obtain the captured value. The captured value is fixed, and does not change if the underlying Value is updated separately.

A linked snapshot is either "valid" or "invalid". It is "valid" if a call to [Linked.StoreCond] could succeed at some point in the future; otherwise it is "invalid". A valid snapshot may become invalid, but an invalid snapshot is permanently so. See also: [Linked.Validate].

func (*Link[T]) Get added in v0.7.0

func (lv *Link[T]) Get() T

Get returns the value captured in the snapshot.

func (*Link[T]) StoreCond added in v0.7.0

func (lv *Link[T]) StoreCond(v T) bool

StoreCond attempts to update the linked Value with v, and reports whether the update succeeded. An update succeeds if no successful StoreCond or Set operation has been applied to the linked Value since the Value.LoadLink that initialized lv.

Once StoreCond has been called, whether successful or not, lv is forever invalid (until re-linked). If it succeeded, the Get method returns the updated value.

func (*Link[T]) Validate added in v0.7.0

func (lv *Link[T]) Validate() bool

Validate reports whether a call to StoreCond would have succeeded given the current state of lv. When Validate reports true, it means lv was valid at the time of the call; it may have become invalid by the time the caller receives the result. If Validate reports false, lv is forever invalid (until re-linked).

type Value added in v0.0.2

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

A Value is a mutable container for a single value of type T that can be concurrently accessed by multiple goroutines. A zero Value is ready for use, but must not be copied after its first use.

The Value takes ownership of the value in its custody. In particular, if a pointer or a slice is stored in a Value, the caller must not modify the contents without separate synchronization.

func NewValue added in v0.0.2

func NewValue[T any](init T) *Value[T]

NewValue creates a new Value with the given initial value.

func (*Value[T]) Get added in v0.0.2

func (v *Value[T]) Get() T

Get returns the current value stored in v.

func (v *Value[T]) LoadLink(lv *Link[T]) *Link[T]

LoadLink links a view of the current value of v. If lv == nil, a new link is allocated and returned. Otherwise, the contents of *lv are replaced and lv is returned.

func (*Value[T]) Set added in v0.0.2

func (v *Value[T]) Set(newValue T)

Set updates the value stored in v to newValue. Calling Set also wakes any goroutines that are blocked in the Wait method. Set invalidates any linked snapshots open on v, even if the target value does not change.

func (*Value[T]) Wait added in v0.0.2

func (v *Value[T]) Wait() <-chan T

Wait returns a new channel that blocks until the value of v changes, then delivers the current value of v. Each call to Wait returns a new channel. Once a value has been delivered to the channel, it is closed.

If multiple goroutines set v concurrently, the channel will deliver the value from one of them, but not necessarily the first.

Directories

Path Synopsis
Package throttle allows calls to a function to be coalesced among multiple concurrent goroutines.
Package throttle allows calls to a function to be coalesced among multiple concurrent goroutines.
Package trigger implements channel-based condition variable.
Package trigger implements channel-based condition variable.

Jump to

Keyboard shortcuts

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