Documentation ¶
Overview ¶
The signalbus package provides a simple way to issue notifications that named events have occurred.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PgSignalBus ¶
type PgSignalBus struct {
// contains filtered or unexported fields
}
PgSignalBus implements a signalbus.SignalBus that is clustered using postgresql notify events.
func NewPgSignalBus ¶
func NewPgSignalBus(signalBus SignalBus, db *gorm.DB, connectDSN string, logger *zap.SugaredLogger) *PgSignalBus
NewSignalBusService creates a new PgSignalBus
func (*PgSignalBus) Notify ¶
func (pgsb *PgSignalBus) Notify(name string)
Notify will notify all the subscriptions created across the cluster of the given named signal.
func (*PgSignalBus) NotifyAll ¶
func (pgsb *PgSignalBus) NotifyAll()
func (*PgSignalBus) Start ¶
func (pgsb *PgSignalBus) Start(ctx context.Context, wg *sync.WaitGroup)
Start starts the background worker that listens for the events that are sent from this process and all other processes publishing to the signalbus channel.
func (*PgSignalBus) Subscribe ¶
func (pgsb *PgSignalBus) Subscribe(name string) *Subscription
Subscribe creates a subscription the named signal. They are performed on the in memory bus.
type SignalBus ¶
type SignalBus interface { // Notify will notify all the subscriptions created for the given named signal. Notify(name string) // NotifyAll will notify all the subscriptions NotifyAll() // Subscribe creates a subscription the named signal Subscribe(name string) *Subscription }
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
func (*Subscription) Close ¶
func (sub *Subscription) Close()
Close is used to close out the subscription.
func (*Subscription) IsSignaled ¶
func (sub *Subscription) IsSignaled() bool
IsSignaled checks to see if the subscription has been notified.
func (*Subscription) Signal ¶
func (sub *Subscription) Signal() <-chan struct{}
Signal returns a channel that receives a true message when the subscription is notified.
Signal is provided for use in select statements:
func WatchTheKey(sb *signalBus) error { sub := sb.Subscribe("the-key") defer sub.Close() for { select { case <-sub.Signal(): // this waits for the signal to occur.. fmt.Print("the-key was signaled.") } } }