package xsync
import "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsync"
Index ¶
- func NewLastUsage(opts ...lastUsageOption) *lastUsage
- func OnceFunc(f func(ctx context.Context) error) func(ctx context.Context) error
- func WithClock(clock clockwork.Clock) lastUsageOption
- func WithLock[T any](l mutex, f func() T) T
- func WithRLock[T any](l rwMutex, f func() T) T
- type EventBroadcast
- type LastUsage
- type Map
- func (m *Map[K, V]) Clear() (removed int)
- func (m *Map[K, V]) Delete(key K) bool
- func (m *Map[K, V]) Extract(key K) (value V, ok bool)
- func (m *Map[K, V]) Get(key K) (value V, ok bool)
- func (m *Map[K, V]) Has(key K) bool
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) Must(key K) (value V)
- func (m *Map[K, V]) Range(f func(key K, value V) bool)
- func (m *Map[K, V]) Set(key K, value V)
- type Mutex
- type Once
- func OnceValue[T closer.Closer](f func() (T, error)) *Once[T]
- func (v *Once[T]) Close(ctx context.Context) (err error)
- func (v *Once[T]) Get() (T, error)
- func (v *Once[T]) Must() T
- type OneTimeWaiter
- type Pool
- type RWMutex
- type Set
- func (s *Set[T]) Add(key T) bool
- func (s *Set[T]) Clear() (removed int)
- func (s *Set[T]) Has(key T) bool
- func (s *Set[T]) Range(f func(key T) bool)
- func (s *Set[T]) Remove(key T) bool
- func (s *Set[T]) Size() int
- func (s *Set[T]) Values() []T
- type SoftWeightedSemaphore
- func NewSoftWeightedSemaphore(n int64) *SoftWeightedSemaphore
- func (s *SoftWeightedSemaphore) Acquire(ctx context.Context, n int64) error
- func (s *SoftWeightedSemaphore) Release(n int64)
- func (s *SoftWeightedSemaphore) TryAcquire(n int64) bool
- type UnboundedChan
- func NewUnboundedChan[T any]() *UnboundedChan[T]
- func (c *UnboundedChan[T]) Close()
- func (c *UnboundedChan[T]) Receive(ctx context.Context) (T, bool, error)
- func (c *UnboundedChan[T]) Send(msg T)
- func (c *UnboundedChan[T]) SendWithMerge(msg T, mergeFunc func(last, new T) (T, bool))
- type Value
Functions ¶
func NewLastUsage ¶
func NewLastUsage(opts ...lastUsageOption) *lastUsage
func OnceFunc ¶
func WithClock ¶
func WithLock ¶
func WithLock[T any](l mutex, f func() T) T
func WithRLock ¶
func WithRLock[T any](l rwMutex, f func() T) T
Types ¶
type EventBroadcast ¶
type EventBroadcast struct {
// contains filtered or unexported fields
}
EventBroadcast is implementation of broadcast notify about event Zero value is usable, must not copy after first call any method
func (*EventBroadcast) Broadcast ¶
func (b *EventBroadcast) Broadcast()
func (*EventBroadcast) Waiter ¶
func (b *EventBroadcast) Waiter() OneTimeWaiter
Waiter return channel, that will close when next event will be broadcast. For prevent race between subscribe and event client code must subscribe at first, then check condition if false - wait closing channed and check condition again
type LastUsage ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
func (*Map[K, V]) Clear ¶
func (*Map[K, V]) Delete ¶
func (*Map[K, V]) Extract ¶
func (*Map[K, V]) Get ¶
func (*Map[K, V]) Has ¶
func (*Map[K, V]) Len ¶
func (*Map[K, V]) Must ¶
func (m *Map[K, V]) Must(key K) (value V)
func (*Map[K, V]) Range ¶
func (*Map[K, V]) Set ¶
func (m *Map[K, V]) Set(key K, value V)
type Mutex ¶
func (*Mutex) WithLock ¶
func (l *Mutex) WithLock(f func())
type Once ¶
func OnceValue ¶
func (*Once[T]) Close ¶
func (*Once[T]) Get ¶
func (*Once[T]) Must ¶
func (v *Once[T]) Must() T
type OneTimeWaiter ¶
type OneTimeWaiter struct {
// contains filtered or unexported fields
}
func (*OneTimeWaiter) Done ¶
func (w *OneTimeWaiter) Done() <-chan struct{}
type Pool ¶
type Pool[T any] struct { New func() *T // contains filtered or unexported fields }
func (*Pool[T]) GetOrNew ¶
func (p *Pool[T]) GetOrNew() *T
func (*Pool[T]) GetOrNil ¶
func (p *Pool[T]) GetOrNil() *T
func (*Pool[T]) Put ¶
func (p *Pool[T]) Put(t *T)
type RWMutex ¶
func (*RWMutex) WithLock ¶
func (l *RWMutex) WithLock(f func())
func (*RWMutex) WithRLock ¶
func (l *RWMutex) WithRLock(f func())
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
func (*Set[T]) Add ¶
func (*Set[T]) Clear ¶
func (*Set[T]) Has ¶
func (*Set[T]) Range ¶
func (*Set[T]) Remove ¶
func (*Set[T]) Size ¶
func (*Set[T]) Values ¶
func (s *Set[T]) Values() []T
type SoftWeightedSemaphore ¶
type SoftWeightedSemaphore struct {
// contains filtered or unexported fields
}
SoftWeightedSemaphore extends semaphore.Weighted with ability to acquire one request over capacity if semaphore is completely free
func NewSoftWeightedSemaphore ¶
func NewSoftWeightedSemaphore(n int64) *SoftWeightedSemaphore
NewSoftWeightedSemaphore creates new SoftWeightedSemaphore with given capacity
func (*SoftWeightedSemaphore) Acquire ¶
func (s *SoftWeightedSemaphore) Acquire(ctx context.Context, n int64) error
Acquire acquires the semaphore with a weight of n. If the semaphore is completely free, the acquisition will succeed regardless of weight.
func (*SoftWeightedSemaphore) Release ¶
func (s *SoftWeightedSemaphore) Release(n int64)
Release releases n tokens back to the semaphore.
func (*SoftWeightedSemaphore) TryAcquire ¶
func (s *SoftWeightedSemaphore) TryAcquire(n int64) bool
TryAcquire tries to acquire the semaphore with a weight of n without blocking. If the semaphore is completely free, the acquisition will succeed regardless of weight.
type UnboundedChan ¶
type UnboundedChan[T any] struct { // contains filtered or unexported fields }
UnboundedChan is a generic unbounded channel implementation that supports message merging and concurrent access.
func NewUnboundedChan ¶
func NewUnboundedChan[T any]() *UnboundedChan[T]
NewUnboundedChan creates a new UnboundedChan instance.
func (*UnboundedChan[T]) Close ¶
func (c *UnboundedChan[T]) Close()
Close closes the channel. After closing, Send and SendWithMerge operations will be ignored, and Receive will return (zero_value, false) once the buffer is empty.
func (*UnboundedChan[T]) Receive ¶
func (c *UnboundedChan[T]) Receive(ctx context.Context) (T, bool, error)
Receive retrieves a message from the channel with context support. Returns (message, true, nil) if a message is available. Returns (zero_value, false, nil) if the channel is closed and empty. Returns (zero_value, false, context.Canceled) if context is cancelled. Returns (zero_value, false, context.DeadlineExceeded) if context times out.
func (*UnboundedChan[T]) Send ¶
func (c *UnboundedChan[T]) Send(msg T)
Send adds a message to the channel. The operation is non-blocking and thread-safe.
func (*UnboundedChan[T]) SendWithMerge ¶
func (c *UnboundedChan[T]) SendWithMerge(msg T, mergeFunc func(last, new T) (T, bool))
SendWithMerge adds a message to the channel with optional merging. If mergeFunc returns true, the new message will be merged with the last message. The merge operation is atomic and preserves message order.
type Value ¶
type Value[T any] struct { // contains filtered or unexported fields }
func NewValue ¶
func (*Value[T]) Change ¶
func (v *Value[T]) Change(change func(old T) T)
func (*Value[T]) Get ¶
func (v *Value[T]) Get() T
Source Files ¶
event_broadcast.go last_usage_guard.go last_usage_guard_start.go map.go mutex.go once.go pool.go set.go soft_semaphore.go unbounded_chan.go value.go
- Version
- v3.110.0 (latest)
- Published
- Jun 10, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 3 hours ago –
Tools for package owners.