Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pub ¶
type Pub[T any] struct { // contains filtered or unexported fields }
Pub is a channel-based broadcast FIFO queue. Built on top of Queue, the Pub sends published messages to all active Subs created via the NewSub method.
Example ¶
pub := queue.NewPub[string]() defer pub.Close() sub1 := pub.NewSub() sub2 := pub.NewSub() defer sub1.Close() defer sub2.Close() pub.Pub("item") out1 := <-sub1.Sub() fmt.Printf("sub1 received: %v\n", out1) out2 := <-sub2.Sub() fmt.Printf("sub2 received: %v\n", out2)
Output: sub1 received: item sub2 received: item
func NewPub ¶
NewPub returns a new Pub. Remember to call Close on the Pub once you're finished with it.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue is a channel-based FIFO queue. Similar to a Go channel, items can be pushed to the back of the Queue and then popped off the front by listening on the Pop channel. This structure differs from channels in that its buffer is effectively endless.
Example ¶
q := queue.New[string]() defer q.Close() q.Push("item") out := <-q.Pop() fmt.Printf("received: %v\n", out)
Output: received: item
Click to show internal directories.
Click to hide internal directories.