Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pub ¶
type Pub 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 ¶
package main import ( "fmt" "github.com/jimjibone/queue" ) func main() { pub := queue.NewPub() 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 ¶
func NewPub() *Pub
NewPub returns a new Pub. Remember to call Close on the Pub once you're finished with it.
type Queue ¶
type Queue 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 ¶
package main import ( "fmt" "github.com/jimjibone/queue" ) func main() { q := queue.New() defer q.Close() q.Push("item") out := <-q.Pop() fmt.Printf("received: %v\n", out) }
Output: received: item
func New ¶
func New() *Queue
New returns a new, running, Queue. Remember to call Close on the Queue once you're finished with it.
Click to show internal directories.
Click to hide internal directories.