concurrent

package
v1.61.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer added in v1.35.0

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

Buffer is a concurrency-safe bytes.Buffer. It implements io.Writer so it can be used anywhere a plain buffer would, e.g. as the output target for a log handler or as subprocess stderr.

func (*Buffer) Bytes added in v1.60.0

func (b *Buffer) Bytes() []byte

Bytes returns a copy of the buffered content as a byte slice. The returned slice is safe to retain and modify.

func (*Buffer) Drain added in v1.35.0

func (b *Buffer) Drain() string

Drain returns the buffered content and resets the buffer atomically.

func (*Buffer) Len added in v1.60.0

func (b *Buffer) Len() int

Len returns the number of bytes currently buffered.

func (*Buffer) Reset added in v1.35.0

func (b *Buffer) Reset()

Reset clears the buffer.

func (*Buffer) String added in v1.35.0

func (b *Buffer) String() string

String returns the buffered content.

func (*Buffer) Write added in v1.35.0

func (b *Buffer) Write(p []byte) (int, error)

Write appends p to the buffer.

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewMap

func NewMap[K comparable, V any]() *Map[K, V]

func (*Map[K, V]) Clear added in v1.60.0

func (m *Map[K, V]) Clear()

Clear removes all entries from the map.

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) Length

func (m *Map[K, V]) Length() int

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) (V, bool)

func (*Map[K, V]) LoadOrStore added in v1.60.0

func (m *Map[K, V]) LoadOrStore(key K, value V) (V, bool)

LoadOrStore returns the existing value for key if present; otherwise it stores and returns value. The loaded result is true if the value was loaded, false if stored.

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(key K, value V) bool)

Range calls f for every key/value pair in the map. Iteration stops early if f returns false.

Range iterates over a snapshot of the map taken under a read lock; f is invoked without holding any lock, which means callbacks may safely call other methods on the same Map (including Store and Delete) without deadlocking. As a consequence, mutations performed during iteration are not reflected in the values seen by f.

func (*Map[K, V]) Store

func (m *Map[K, V]) Store(key K, value V)

type Slice

type Slice[V any] struct {
	// contains filtered or unexported fields
}

func NewSlice

func NewSlice[V any]() *Slice[V]

func (*Slice[V]) All

func (s *Slice[V]) All() []V

func (*Slice[V]) Append

func (s *Slice[V]) Append(value V)

func (*Slice[V]) Clear

func (s *Slice[V]) Clear()

func (*Slice[V]) Find

func (s *Slice[V]) Find(predicate func(V) bool) (V, int)

Find returns the first element for which predicate returns true, along with its index, or the zero value and -1 if no element matches.

predicate is invoked while a read lock is held on the slice. It must not call methods that acquire the write lock (Append, Set, Update, Clear) on the same Slice, or a deadlock will occur.

func (*Slice[V]) Get

func (s *Slice[V]) Get(index int) (V, bool)

func (*Slice[V]) Length

func (s *Slice[V]) Length() int

func (*Slice[V]) Range

func (s *Slice[V]) Range(f func(index int, value V) bool)

Range calls f for every element in the slice. Iteration stops early if f returns false.

f is invoked while a read lock is held on the slice. Callbacks must not call methods that acquire the write lock (Append, Set, Update, Clear) on the same Slice, or a deadlock will occur.

func (*Slice[V]) Set

func (s *Slice[V]) Set(index int, value V) bool

func (*Slice[V]) Update

func (s *Slice[V]) Update(index int, f func(V) V) bool

Update replaces the element at index with the result of f applied to the current value, returning true on success. If index is out of range, Update returns false and f is not called.

f is invoked while the write lock is held on the slice. It must not call any other method on the same Slice, or a deadlock will occur.

Jump to

Keyboard shortcuts

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