subscribe

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrServerShuttingDown = errors.New("subscription server shutting down")

ErrServerShuttingDown is an error returned in case the server is in the process of shutting down.

Functions

This section is empty.

Types

type Client

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

Client is used to get notified about updates the caller has subscribed to,

func (*Client) Cancel

func (c *Client) Cancel()

Cancel should be called in case the client no longer wants to subscribe for updates from the server.

func (*Client) Quit

func (c *Client) Quit() <-chan struct{}

Quit is a channel that will be closed in case the server decides to no longer deliver updates to this client.

func (*Client) Updates

func (c *Client) Updates() <-chan interface{}

Updates returns a read-only channel where the updates the client has subscribed to will be delivered.

type Server

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

Server is a struct that manages a set of subscriptions and their corresponding clients. Any update will be delivered to all active clients.

func NewServer

func NewServer() *Server

NewServer returns a new Server.

func (*Server) SendUpdate

func (s *Server) SendUpdate(update interface{}) error

SendUpdate is called to send the passed update to all currently active subscription clients.

func (*Server) Start

func (s *Server) Start() error

Start starts the Server, making it ready to accept subscriptions and updates.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the server.

func (*Server) Subscribe

func (s *Server) Subscribe() (*Client, error)

Subscribe returns a Client that will receive updates any time the Server is made aware of a new event.

type Subscription

type Subscription interface {
	// Updates returns a read-only channel where the updates the client has
	// subscribed to will be delivered.
	Updates() <-chan interface{}

	// Quit is a channel that will be closed in case the server decides to
	// no longer deliver updates to this client.
	Quit() <-chan struct{}

	// Cancel should be called in case the client no longer wants to
	// subscribe for updates from the server.
	Cancel()
}

Subscription is an interface implemented by subscriptions to a server providing updates.

Jump to

Keyboard shortcuts

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