pubsub

package
Version: v0.2103.7 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package pubsub implements a generic publish-subscribe interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

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

Broker is a pub/sub broker instance.

func NewBroker

func NewBroker(pubLastOnSubscribe bool) *Broker

NewBroker creates a new pub/sub broker. If pubLastOnSubscribe is set, the last broadcasted value will automatically be published to new subscribers, if one exists.

func NewBrokerEx

func NewBrokerEx(onSubscribeHook OnSubscribeHook) *Broker

NewBrokerEx creates a new pub/sub broker, with a hook to be called when a new subscriber is registered.

func (*Broker) Broadcast

func (b *Broker) Broadcast(v interface{})

Broadcast queues up a new value to be broadcasted.

Note: This makes no special effort to avoid deadlocking if any one of the subscribers' channel is full.

func (*Broker) Subscribe

func (b *Broker) Subscribe() *Subscription

Subscribe subscribes to the Broker's broadcasts, and returns a subscription handle that can be used to receive broadcasts.

Note: The returned subscription's channel will have an unbounded capacity, use SubscribeBuffered to use a bounded ring channel.

func (*Broker) SubscribeBuffered

func (b *Broker) SubscribeBuffered(buffer int64) *Subscription

SubscribeBuffered subscribes to the Broker's broadcasts, and returns a subscription handle that can be used to receive broadcasts.

Buffer controls the capacity of a ring buffer - when buffer is full the oldest value will be discarded. In case buffer is negative (or zero) an unbounded channel is used.

func (*Broker) SubscribeEx

func (b *Broker) SubscribeEx(buffer int64, onSubscribeHook OnSubscribeHook) *Subscription

SubscribeEx subscribes to the Broker's broadcasts, and returns a subscription handle that can be used to receive broadcasts. In addition it also takes a per-subscription on-subscribe callback hook.

Note: If there is a Broker wide hook set, it will be called after the per-subscription hook is called.

type ClosableSubscription

type ClosableSubscription interface {
	// Close unsubscribes the subscription.
	Close()
}

ClosableSubscription is an interface for a subscription that can be closed. This can be used as return value from methods instead of the actual Subscription to expose a more limited interface.

func NewContextSubscription

func NewContextSubscription(ctx context.Context) (context.Context, ClosableSubscription)

NewContextSubscription creates a subscription that cancels the context when closed.

type OnSubscribeHook

type OnSubscribeHook func(channels.Channel)

OnSubscribeHook is the on-subscribe callback hook prototype.

type Subscription

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

Subscription is a Broker subscription instance.

func (*Subscription) Close

func (s *Subscription) Close()

Close unsubscribes from the Broker.

func (*Subscription) Untyped

func (s *Subscription) Untyped() <-chan interface{}

Untyped returns the subscription's untyped output. Effort should be made to use Unwrap instead.

func (*Subscription) Unwrap

func (s *Subscription) Unwrap(ch interface{})

Unwrap ties the read end of the provided channel to the subscription's output.

Source Files

Jump to

Keyboard shortcuts

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