Documentation
¶
Index ¶
- Variables
- type Graph
- type Router
- func (g *Router) Broadcast(msg []byte)
- func (g *Router) Follow(followerID, followedID int)
- func (g *Router) Reset()
- func (g *Router) SendMsg(userID int, msg []byte)
- func (g *Router) SendMsgToFollowers(userID int, msg []byte)
- func (g *Router) Subscribe(userID int, c chan<- []byte) (UnsubscribeFunc, <-chan struct{}, error)
- func (g *Router) Unfollow(followerID, followedID int)
- type Subscriber
- type UnsubscribeFunc
Constants ¶
This section is empty.
Variables ¶
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 (*Router) Broadcast ¶
Broadcast sends message msg to all connected users.
func (*Router) Follow ¶
Follow adds followerID to list of followers of user identified by followedID.
func (*Router) SendMsg ¶
SendMsg sends message msg to connected clients registered with userID identifier.
func (*Router) SendMsgToFollowers ¶
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.
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