Documentation ¶
Overview ¶
Package pubsub provides the core functionalities to handle publication/subscription pipelines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CancelFunc ¶
type CancelFunc func() error
type Command ¶
type Command struct { // Topic is the subscription topic. Topic string // Run will be called each time that the pubsub receives // new data on Topic. Run Action // PostRun is triggered before terminating the subscription // pipeline. PostRun func(error) // Ref is filled with the subscription index reference. Ref int }
Command contains fields used in a subscription pipeline.
type PubSub ¶
type PubSub struct { MaxSubs int // maximum number of subscribers sync.Mutex // contains filtered or unexported fields }
PubSub wraps the core pubsub functionalities.
func (*PubSub) Pub ¶
Pub broadcasts the message to the listeners of topic. unsubscribes a channel if it is closed when sending to it. (i.e. causes a panic)
func (*PubSub) Sub ¶
func (ps *PubSub) Sub(cmd *Command) (CancelFunc, error)
Sub subscribes cmd to cmd.Topic in the pubsub. If there is no such topic it creates it. Returns a cancel function that can be used to terminate the subscription. cmd.Run gets called for each data coming from the pubsub. PostRun gets as argument the returned value of Run. Returns an error if the command does not contain at least a topic and a Run function.