You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
606 B
Go

package httputil_test
import (
"net/http"
"testing"
"time"
"git.phc.dm.unipi.it/aziis98/posti-dm/server/httputil"
)
func TestSSE(t *testing.T) {
var broadcastChannel chan<- string
go func() {
for {
if broadcastChannel != nil {
broadcastChannel <- "Messaggio per tutti"
}
time.Sleep(1 * time.Second)
}
}()
http.Handle("/sse", httputil.HandleSSE(func(broadcast, single chan<- string) {
broadcastChannel = broadcast
time.Sleep(1 * time.Second)
single <- "Messaggio 1 per questo client"
single <- "Messaggio 2 per questo client"
}))
http.ListenAndServe(":8000", nil)
}