pubsub

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package pubsub contains types to deal with subscriptions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PubSub

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

PubSub deals with subscribing and publishing messages.

func New

func New(historyCap int) *PubSub

New creates a new PubSub. It will keep a history for each message type with at least the given cap.

func (*PubSub) LastMessageID added in v0.2.2

func (p *PubSub) LastMessageID() uint64

LastMessageID returns the ID of the last message.

func (*PubSub) Publish

func (p *PubSub) Publish(messageType string, message interface{})

Publish will publish a message of the given type to all subscribers for that type.

func (*PubSub) Subscribe

func (p *PubSub) Subscribe(
	ctx context.Context,
	messageType string,
	since uint64,
	fn func(interface{}),
)

Subscribe register a function that will receive messages of the given type. To unsubscribe the context must be closed.

Jump to

Keyboard shortcuts

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