NewRelayWithContext() and Close().

This commit is contained in:
fiatjaf
2024-02-19 06:33:49 -03:00
parent e174dd6a95
commit 8df7c9d773
3 changed files with 51 additions and 27 deletions

View File

@@ -2,6 +2,7 @@ package khatru
import (
"context"
"fmt"
"net"
"net/http"
"strconv"
@@ -48,6 +49,8 @@ func (rl *Relay) Start(host string, port int, started ...chan bool) error {
// Shutdown sends a websocket close control message to all connected clients.
func (rl *Relay) Shutdown(ctx context.Context) {
rl.cancel(fmt.Errorf("Shutdown called"))
rl.httpServer.Shutdown(ctx)
rl.clients.Range(func(conn *websocket.Conn, _ struct{}) bool {