pool

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool manages a group of websocket connections. It is responsible for upgrading connections of new clients, reading and serializing messages from them. It also allows to broadcast a message to the entire pool.

func NewPool

func NewPool(l *log.Logger) *Pool

NewPool creates and properly initializes a pool.

func (*Pool) AddToPool

func (p *Pool) AddToPool(w http.ResponseWriter, r *http.Request,
	messageType int, initialMessages [][]byte)

AddToPool is the intended way to add a client to the pool. It can be used inside an http.HandlerFunc. initialMessages is the array of message bodies that are going to be sent to the client before every other update from the pool. messageType specifies the type of each one of the initial messages.

func (*Pool) CloseAll

func (p *Pool) CloseAll()

CloseAll shuts down all the clients in the pool. Make sure to invoke it before deleting the pool, otherwise it will lead to goroutine leaks.

func (*Pool) ReadQueue

func (p *Pool) ReadQueue() <-chan []byte

ReadQueue returns the readQueue of the pool. To read a message use <-pool.ReadQueue(). The choice of returning the channel instead of waiting for the next message and returning it is motivated by the advantage in "select" statement of the former approach.

func (*Pool) SendMessageToAll

func (p *Pool) SendMessageToAll(messageType int, data []byte)

SendMessageToAll broadcasts data to all the clients in the pool. messageType is the integer associated to the type of websocket message, an example value for messageType is websocket.TextMessage where websocket refers to github.com/gorilla/websocket package.

Jump to

Keyboard shortcuts

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