pubsub

package
v20.10.9+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Publisher

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

Publisher is basic pub/sub structure. Allows to send events and subscribe to them. Can be safely used from multiple goroutines.

func NewPublisher

func NewPublisher(publishTimeout time.Duration, buffer int) *Publisher

NewPublisher creates a new pub/sub publisher to broadcast messages. The duration is used as the send timeout as to not block the publisher publishing messages to other clients if one client is slow or unresponsive. The buffer is used when creating new channels for subscribers.

func (*Publisher) Close

func (p *Publisher) Close()

Close closes the channels to all subscribers registered with the publisher.

func (*Publisher) Evict

func (p *Publisher) Evict(sub chan interface{})

Evict removes the specified subscriber from receiving any more messages.

func (*Publisher) Len

func (p *Publisher) Len() int

Len returns the number of subscribers for the publisher

func (*Publisher) Publish

func (p *Publisher) Publish(v interface{})

Publish sends the data in v to all subscribers currently registered with the publisher.

func (*Publisher) Subscribe

func (p *Publisher) Subscribe() chan interface{}

Subscribe adds a new subscriber to the publisher returning the channel.

func (*Publisher) SubscribeTopic

func (p *Publisher) SubscribeTopic(topic topicFunc) chan interface{}

SubscribeTopic adds a new subscriber that filters messages sent by a topic.

func (*Publisher) SubscribeTopicWithBuffer

func (p *Publisher) SubscribeTopicWithBuffer(topic topicFunc, buffer int) chan interface{}

SubscribeTopicWithBuffer adds a new subscriber that filters messages sent by a topic. The returned channel has a buffer of the specified size.

Jump to

Keyboard shortcuts

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