Skip to content

A set of Write-functions to make gorilla/websocket's write to connection be blocking if another Write-function was using the connection

Notifications You must be signed in to change notification settings

xiaodaigh/wsumm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

wsumm

Wrapper functions to make gorilla/websocket's WriteFunctions i.e. WriteMessage and WriteJSON be blocking if another Writefunction of the same channel is being run.

Installation

In command line

go get github.com/xiaodaigh/wsumm

Example Usage

package test_wsumm

import (
	"github.com/gorilla/websocket"
	"github.com/xiaodaigh/wsumm"
	"net/http"
)

var upgrader = wsumm.Upgrader{
	Upgrader: &websocket.Upgrader{
		ReadBufferSize:  1024,
		WriteBufferSize: 1024,
	}}

func someHandler(w http.ResponseWriter, r *http.Request) {
	conn, _ := upgrader.Upgrade(w, r, nil)
	go func() {
		for i := 0; i < 1000; i++ {
			conn.WriteMessage(websocket.TextMessage, []byte("testing"))
		}
	}()
	go func() {
		for i := 0; i < 1000; i++ {
			conn.WriteJSON(struct{}{})
		}
	}()
}

About

A set of Write-functions to make gorilla/websocket's write to connection be blocking if another Write-function was using the connection

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages