Documentation
¶
Index ¶
- Variables
- func CountAppearances[T comparable](items []T) map[T]int
- func DecodeOrderPreservingVarUint64(bytes []byte) (uint64, int, error)
- func EncodeOrderPreservingVarUint64(number uint64) []byte
- func ExtractServerAddress(ctx context.Context) string
- func FileExists(path string) bool
- func IsConfigTx(namespaces []*applicationpb.TxNamespace) bool
- func Must(err error, msg ...string)
- func MustRead(source io.Reader, size int) []byte
- func ProcessErr(err error, msg string) error
- type ConcurrencyLimiter
- type LazyJSON
- type Slots
- type SyncMap
- func (m *SyncMap[K, V]) Clear()
- func (m *SyncMap[K, V]) CompareAndDelete(key K, value V) (deleted bool)
- func (m *SyncMap[K, V]) CompareAndSwap(key K, oldVal, newVal V) (swapped bool)
- func (m *SyncMap[K, V]) Count() int
- func (m *SyncMap[K, V]) Delete(key K)
- func (m *SyncMap[K, V]) IterItems() iter.Seq2[K, V]
- func (m *SyncMap[K, V]) IterKeys() iter.Seq[K]
- func (m *SyncMap[K, V]) IterValues() iter.Seq[V]
- func (m *SyncMap[K, V]) Load(key K) (value V, ok bool)
- func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *SyncMap[K, V]) Range(f func(key K, value V) bool)
- func (m *SyncMap[K, V]) Store(key K, value V)
- func (m *SyncMap[K, V]) Swap(key K, value V) (previous V, loaded bool)
Constants ¶
This section is empty.
Variables ¶
var ErrActiveStream = errors.New("a stream is already active. Only one active stream is allowed at a time")
ErrActiveStream represents the error when attempting to create a new stream while one is already active. The system only allows a single active stream at any given time.
Functions ¶
func CountAppearances ¶ added in v0.1.5
func CountAppearances[T comparable](items []T) map[T]int
CountAppearances returns the number of appearances each item have.
func DecodeOrderPreservingVarUint64 ¶
DecodeOrderPreservingVarUint64 decodes the number from the bytes obtained from method 'EncodeOrderPreservingVarUint64'. It returns the decoded number, the number of bytes that are consumed in the process, and an error if the input bytes are invalid.
func EncodeOrderPreservingVarUint64 ¶
EncodeOrderPreservingVarUint64 returns a byte-representation for a uint64 number such that all zero-bits starting bytes are trimmed in order to reduce the length of the array For preserving the order in a default bytes-comparison, first byte contains the number of remaining bytes. The presence of first byte also allows to use the returned bytes as part of other larger byte array such as a composite-key representation in db.
func ExtractServerAddress ¶ added in v0.1.8
ExtractServerAddress returns the stream's server (local) address.
func IsConfigTx ¶ added in v0.1.8
func IsConfigTx(namespaces []*applicationpb.TxNamespace) bool
IsConfigTx returns true if the namespaces indicate a config transaction.
func MustRead ¶ added in v0.1.6
MustRead reads a byte array of the given size from the source. It panics if the read fails, or cannot read the requested size. "crypto/rand" and "math/rand" never fail and always returns the correct length.
func ProcessErr ¶
ProcessErr wraps a non-nil error with a message using %w for unwrapping. Returns nil if the error is nil, otherwise returns the wrapped error. Example to the call of the function: utils.ProcessErr(g.Wait(), "sidecar has been stopped").
Types ¶
type ConcurrencyLimiter ¶ added in v0.1.9
type ConcurrencyLimiter struct {
// contains filtered or unexported fields
}
ConcurrencyLimiter tracks active counter with an optional max limit. If limit <= 0, the counter is unbounded.
func NewConcurrencyLimiter ¶ added in v0.1.9
func NewConcurrencyLimiter(limit int) *ConcurrencyLimiter
NewConcurrencyLimiter creates a limiter with the given max limit.
func (*ConcurrencyLimiter) Load ¶ added in v0.1.9
func (c *ConcurrencyLimiter) Load() int64
Load returns the current active count.
func (*ConcurrencyLimiter) Release ¶ added in v0.1.9
func (c *ConcurrencyLimiter) Release()
Release decrements the active counter by 1.
func (*ConcurrencyLimiter) TryAcquire ¶ added in v0.1.9
func (c *ConcurrencyLimiter) TryAcquire(ctx context.Context) bool
TryAcquire increments the active counter by 1 if capacity is available. Returns true if the slot was acquired, false if the limit has been reached or the context is done.
type Slots ¶
type Slots struct {
// contains filtered or unexported fields
}
Slots manages a resource counter, allowing callers to block until at least one slot is available.
func (*Slots) Acquire ¶
Acquire blocks until at least one slot is available or the context is canceled. It then reduces the available slot count by n.
func (*Slots) Broadcast ¶
func (w *Slots) Broadcast()
Broadcast wakes up all goroutines waiting to acquire slots.
func (*Slots) WaitTillEmpty ¶ added in v0.1.8
WaitTillEmpty waits till all available slots are empty.
type SyncMap ¶
type SyncMap[K, V any] struct { // contains filtered or unexported fields }
SyncMap is a wrapper for sync.Map. It enhances readability by explicitly specifying the key and value types at compile time. This also minimizes boilerplate code needed for type casting.
func (*SyncMap[K, V]) Clear ¶
func (m *SyncMap[K, V]) Clear()
Clear mirrors sync.Map's method. See sync.Map for detailed documentation.
func (*SyncMap[K, V]) CompareAndDelete ¶
CompareAndDelete mirrors sync.Map's method. See sync.Map for detailed documentation.
func (*SyncMap[K, V]) CompareAndSwap ¶
CompareAndSwap mirrors sync.Map's method. See sync.Map for detailed documentation.
func (*SyncMap[K, V]) Count ¶
Count counts the number of items in the map. It iterates over the map, so it is best to avoid it in production.
func (*SyncMap[K, V]) Delete ¶
func (m *SyncMap[K, V]) Delete(key K)
Delete mirrors sync.Map's method. See sync.Map for detailed documentation.
func (*SyncMap[K, V]) IterItems ¶
IterItems allows iterating over the items' key value pair. Example:
for k, v := range m.IterItems() {
fmt.Printf("%v: %v\n", k, v)
}
func (*SyncMap[K, V]) IterKeys ¶
IterKeys allows iterating over the items' keys. Example:
for k := range m.IterKeys() {
fmt.Printf("%v\n", k)
}
func (*SyncMap[K, V]) IterValues ¶
IterValues allows iterating over the items' values. Example:
for v := range m.IterValues() {
fmt.Printf("%v\n", v)
}
func (*SyncMap[K, V]) Load ¶
Load mirrors sync.Map's method. See sync.Map for detailed documentation.
func (*SyncMap[K, V]) LoadAndDelete ¶
LoadAndDelete mirrors sync.Map's method. See sync.Map for detailed documentation.
func (*SyncMap[K, V]) LoadOrStore ¶
LoadOrStore mirrors sync.Map's method. See sync.Map for detailed documentation.
func (*SyncMap[K, V]) Range ¶
Range mirrors sync.Map's method. See sync.Map for detailed documentation.