notifier

package
v1.39.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchTarget

type BatchTarget interface {
	Target
	// BatchMode is called both before and after a series of notifications are
	// about to be broadcast. The target is not guaranteed to have intervening
	// calls to HandleNotification() made to it.
	BatchMode(start bool)
}

BatchTarget defines the methods a target of notifications that wants to be notified when a batch change occurs must implement.

type Notifier

type Notifier struct {
	// contains filtered or unexported fields
}

Notifier tracks targets of notifications and provides methods for notifying them.

func New

func New(recoveryHandler errs.RecoveryHandler) *Notifier

New creates a new notifier.

func (*Notifier) BatchLevel

func (n *Notifier) BatchLevel() int

BatchLevel returns the current batch level.

func (*Notifier) Enabled

func (n *Notifier) Enabled() bool

Enabled returns true if this notifier is currently enabled.

func (*Notifier) EndBatch

func (n *Notifier) EndBatch()

EndBatch informs all BatchTargets that were present when StartBatch() was called that a batch of notifications just finished. If batch level is still greater than zero after being decremented, then no notifications will be made.

func (*Notifier) Notify

func (n *Notifier) Notify(name string, producer interface{})

Notify sends a notification to all interested targets.

func (*Notifier) NotifyWithData

func (n *Notifier) NotifyWithData(name string, data, producer interface{})

NotifyWithData sends a notification to all interested targets. This is a synchronous notification and will not return until all interested targets handle the notification.

func (*Notifier) Register

func (n *Notifier) Register(target Target, priority int, names ...string)

Register a target with this notifier. 'priority' is the relative notification priority, with higher values being delivered first. 'names' are the names the target wishes to consume. Names are hierarchical (separated by a .), so specifying a name of "foo.bar" will consume not only a produced name of "foo.bar", but all sub-names, such as "foo.bar.a", but not "foo.barn" or "foo.barn.a".

func (*Notifier) RegisterFromNotifier

func (n *Notifier) RegisterFromNotifier(other *Notifier)

RegisterFromNotifier adds all registrations from the other notifier into this notifier.

func (*Notifier) Reset

func (n *Notifier) Reset()

Reset removes all targets.

func (*Notifier) SetEnabled

func (n *Notifier) SetEnabled(enabled bool)

SetEnabled sets whether this notifier is enabled or not.

func (*Notifier) StartBatch

func (n *Notifier) StartBatch()

StartBatch informs all BatchTargets that a batch of notifications will be starting. If a previous call to this method was made without a call to EndBatch(), then the batch level will be incremented, but no notifications will be made.

func (*Notifier) Unregister

func (n *Notifier) Unregister(target Target)

Unregister a target.

type Target

type Target interface {
	// HandleNotification is called to deliver a notification.
	HandleNotification(name string, data, producer interface{})
}

Target defines the method a target of notifications must implement.

Jump to

Keyboard shortcuts

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