From 8f540bcf0e238c97b7a60f51110dde1fb73e6faa Mon Sep 17 00:00:00 2001 From: Nikolay Pavlovich Date: Sun, 18 Sep 2022 02:19:20 +0300 Subject: [PATCH] fix example --- examples/basic.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/basic.go b/examples/basic.go index a234ad0..0bc95bd 100644 --- a/examples/basic.go +++ b/examples/basic.go @@ -2,9 +2,11 @@ package main import ( "context" - "github.com/recws-org/recws" + "errors" "log" "time" + + "github.com/recws-org/recws" ) func main() { @@ -28,6 +30,7 @@ func main() { default: if !ws.IsConnected() { log.Printf("Websocket disconnected %s", ws.GetURL()) + time.Sleep(time.Millisecond * 100) // some release cpu while waiting for reconnect continue } @@ -41,6 +44,13 @@ func main() { log.Printf("Error: ReadMessage %s", ws.GetURL()) return } + if err != nil { + if !errors.Is(err, recws.ErrNotConnected) { + log.Printf("Error: ReadMessage %s", ws.GetURL()) + time.Sleep(time.Second * 5) // throttle repeated errors + } + continue // go to next read + } log.Printf("Success: %s", message) }