topic

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package Topic provides a buffered channel with dynamic fanout size. Unlike the normal Go channels, messages sent to a Topic are *duplicated* to all it's receivers. Incoming messages are queued in-memory when a receiver is not ready. Users can add/remove receivers from a topic dynamically.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Receiver

type Receiver[T any] struct {
	// contains filtered or unexported fields
}

func (*Receiver[T]) Unsubscribe

func (r *Receiver[T]) Unsubscribe()

Unsubscribe removes a receiver from a topic. Buffered messages that were not yet received will be discarded.

type Topic

type Topic[T any] struct {
	// contains filtered or unexported fields
}

Topic implements a buffered channel with dynamic fanout.

func New

func New[T any]() *Topic[T]

New creates a new topic.

func (*Topic[T]) Close

func (t *Topic[T]) Close() error

Close destroys the topic. Blocking operations will return with os.ErrClosed error. All receivers are forcibly unsubscribed. Caller is blocked till all background goroutines complete.

func (*Topic[T]) SendCh

func (t *Topic[T]) SendCh() chan<- T

SendCh returns a channel for the Topic where users can send messages. topic in other select clauses. Returns nil if topic is closed.

func (*Topic[T]) Subscribe

func (t *Topic[T]) Subscribe() (*Receiver[T], <-chan T, error)

Subscribe adds a new receiver to the topic. Receiver will receive all future messages from the returned channel.

Jump to

Keyboard shortcuts

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