router

package
v0.0.0-...-140ed45 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChannelAlreadySubscribed is returned by Router.Subscribe calls
	// when client's send channel has been already subscribed.
	ErrChannelAlreadySubscribed = errors.New("client already subscribed")
)

Functions

This section is empty.

Types

type Graph

type Graph interface {
	// Connect creates directed edge between vertices head and tail.
	Connect(head, tail int)

	// Disconnect removes directed edge between vertices head and tail.
	Disconnect(head, tail int)

	// Neighbors returns channel of all direct predecessors of vertex head.
	Neighbors(head int) <-chan int
}

Graph represents a directed graph

type Router

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

Router implements Actions interface.

func New

func New(blockingSend bool) *Router

New returns new Router.

func (*Router) Broadcast

func (g *Router) Broadcast(msg []byte)

Broadcast sends message msg to all connected users.

func (*Router) Follow

func (g *Router) Follow(followerID, followedID int)

Follow adds followerID to list of followers of user identified by followedID.

func (*Router) Reset

func (g *Router) Reset()

Reset resets inverted connections graph.

func (*Router) SendMsg

func (g *Router) SendMsg(userID int, msg []byte)

SendMsg sends message msg to connected clients registered with userID identifier.

func (*Router) SendMsgToFollowers

func (g *Router) SendMsgToFollowers(userID int, msg []byte)

SendMsgToFollowers sends message msg to connected followers of user identified by userID.

func (*Router) Subscribe

func (g *Router) Subscribe(userID int, c chan<- []byte) (UnsubscribeFunc, <-chan struct{}, error)

Subscribe adds user client (its send channel) to Router and returns UnsubscribeFunc. It also returns ErrChannelAlreadySubscribed if the channel has already been subsribed to any userID. Given channel can only subscribe to a single userID, but it's fine to subscribe multiple different channels under the same userID.

func (*Router) Unfollow

func (g *Router) Unfollow(followerID, followedID int)

Unfollow removes followerID from list of followers of user identified by followedID.

type Subscriber

type Subscriber interface {
	Subscribe(id int, c chan<- []byte) (UnsubscribeFunc, <-chan struct{}, error)
}

Subscriber is the interface implemented by UserGraph that wraps the basic Subscribe method.

Subscribe subscribes given channel c under identifier id and returns unsubscribe function (that takes no arguments), empty struct channel (used to broadcast a done signal) and any error that prevented successful subscription.

type UnsubscribeFunc

type UnsubscribeFunc func()

UnsubscribeFunc unsubscribes previously subscribed channel connection.

Source Files

  • graph.go
  • interface.go
  • router.go

Jump to

Keyboard shortcuts

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