pubsub

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPubSub

type IPubSub interface {
	// HaveTopic determines if there are any open pubsub channels for a given topic
	HaveTopic(topic string) bool

	// Listen will "subscribe" to a topic and return a channel that will receive
	// any messages that are published to that topic. Listen accepts an optional
	// identifier that will be used to identify a specific listener. The identifier
	// is useful for being able to close a _specific_ channel.
	Listen(topic string, channelID ...string) chan interface{}

	// Publish will publish a message to a topic, which may have multiple channels associated
	// with it. Each channel will receive the message
	Publish(topic string, m interface{})

	// Close will delete the channel from the topic map and close the channel.
	// WARNING: Make sure to call Close() only on listeners that no longer Listen()'ing
	Close(topic, channelID string)

	// CloseTopic is used when a tail request is stopped to close all associated channels
	// and prevent a dead-lock
	CloseTopic(topic string) bool

	// Reset will delete all channels from the topic map and close all channels;
	// use this when you are finished
	Reset()
}

IPubSub is an interface for an internal, in-memory pub/sub system. We use it to signal events to subscribers (such as when new clients Register() to the server or when disconnects occur). This is used to tell the frontend that a change has occurred (and the frontend must refresh its view.

type PubSub

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

func New

func New() *PubSub

func (*PubSub) Close

func (ps *PubSub) Close(topic, channelID string)

func (*PubSub) CloseTopic

func (ps *PubSub) CloseTopic(topic string) bool

func (*PubSub) HaveTopic

func (ps *PubSub) HaveTopic(topic string) bool

func (*PubSub) Listen

func (ps *PubSub) Listen(topic string, channelID ...string) chan interface{}

func (*PubSub) Publish

func (ps *PubSub) Publish(topic string, m interface{})

func (*PubSub) Reset

func (ps *PubSub) Reset()

Jump to

Keyboard shortcuts

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