generic

package
v1.3.2-rc3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SafeWriteTimeout            = time.Duration(100) * time.Millisecond
	DefaultBroadcastChannelSize = 8
)
View Source
const DefaultRingBufferSize = 16384

Variables

This section is empty.

Functions

func Map

func Map[F any, T any](inputs []F, f func(F) T) []T

Map transforms a slice into a slice of another type

Types

type Broadcaster added in v0.3.29

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

func NewBroadcaster added in v0.3.29

func NewBroadcaster[T any](bufferSize int) *Broadcaster[T]

func (*Broadcaster[T]) Broadcast added in v0.3.29

func (b *Broadcaster[T]) Broadcast(data T) error

Broadcast will send the provided T to all currently subscribed channels as long as the channel is not full (which would cause the broadcaster to block until there was space on that channel).

func (*Broadcaster[T]) Close added in v0.3.29

func (b *Broadcaster[T]) Close()

func (*Broadcaster[T]) IsClosed added in v0.3.29

func (b *Broadcaster[T]) IsClosed() bool

func (*Broadcaster[T]) SetAutoclose added in v0.3.29

func (b *Broadcaster[T]) SetAutoclose(val bool)

func (*Broadcaster[T]) Subscribe added in v0.3.29

func (b *Broadcaster[T]) Subscribe() (chan T, error)

Subscribe allows a client to request future entries and it does this by listening to the channel it is provided.

func (*Broadcaster[T]) Unsubscribe added in v0.3.29

func (b *Broadcaster[T]) Unsubscribe(ch chan T)

Unsubscribe will remove the provided channel (which should have come from a previous call to Subscribe)

type RingBuffer added in v0.3.29

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

func NewRingBuffer added in v0.3.29

func NewRingBuffer[T any](size int) *RingBuffer[T]

func (*RingBuffer[T]) Dequeue added in v0.3.29

func (r *RingBuffer[T]) Dequeue() T

func (*RingBuffer[T]) Drain added in v0.3.29

func (r *RingBuffer[T]) Drain() []T

func (*RingBuffer[T]) Each added in v0.3.29

func (r *RingBuffer[T]) Each(f func(any))

func (*RingBuffer[T]) Enqueue added in v0.3.29

func (r *RingBuffer[T]) Enqueue(data T)

Enqueue will continue to write data to the ring buffer even if nothing is reading from it.

type SyncMap

type SyncMap[K comparable, V any] struct {
	sync.Map
}

A SyncMap is a concurrency-safe sync.Map that uses strongly-typed method signatures to ensure the types of its stored data are known.

func SyncMapFromMap

func SyncMapFromMap[K comparable, V any](m map[K]V) *SyncMap[K, V]

func (*SyncMap[K, V]) Get

func (m *SyncMap[K, V]) Get(key K) (V, bool)

func (*SyncMap[K, V]) Iter

func (m *SyncMap[K, V]) Iter(ranger func(key K, value V) bool)

func (*SyncMap[K, V]) Keys added in v1.0.4

func (m *SyncMap[K, V]) Keys() []K

func (*SyncMap[K, V]) Put

func (m *SyncMap[K, V]) Put(key K, value V)

func (*SyncMap[K, V]) String added in v0.3.25

func (m *SyncMap[K, V]) String() string

Jump to

Keyboard shortcuts

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