signalbus

package
v0.0.0-...-9b598c7 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

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

func ConfigProviders

func ConfigProviders() di.Option

func ServiceProviders

func ServiceProviders() di.Option

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, connectionFactory *db.ConnectionFactory) *PgSignalBus

NewSignalBusService creates a new PgSignalBus

func (*PgSignalBus) Notify

func (sbw *PgSignalBus) Notify(name string)

Notify will notify all the subscriptions created across the cluster of the given named signal.

func (*PgSignalBus) Start

func (sbw *PgSignalBus) Start()

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) Stop

func (sbw *PgSignalBus) Stop()

Stop causes the worker to stop. Blocks until all background go routines complete.

func (*PgSignalBus) Subscribe

func (sbw *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)
	// Subscribe creates a subscription the named signal
	Subscribe(name string) *Subscription
}

func NewSignalBus

func NewSignalBus() SignalBus

NewSignalBus creates a new signalBus

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 bool

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.")
 		}
 	}
}

Jump to

Keyboard shortcuts

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