From 825724d5307c1ea065907cdc4993097bb22e8551 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 21 Jul 2024 08:38:03 +0800 Subject: [PATCH] 2 --- websocket/Recoder.go | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/websocket/Recoder.go b/websocket/Recoder.go index 241e0dc..7d7b018 100644 --- a/websocket/Recoder.go +++ b/websocket/Recoder.go @@ -100,9 +100,10 @@ func Play(filePath string) (s *Server, close func()) { defer timer.Stop() var ( - cu atomic.Int64 - data []byte - e error + cu atomic.Int64 + data []byte + sendData = pslice.New[byte]() + e error ) s.Interface().Pull_tag(map[string]func(any) (disable bool){ @@ -116,10 +117,6 @@ func Play(filePath string) (s *Server, close func()) { default: if d, err := strconv.ParseFloat(data, 64); err == nil && d > 0 { cu.Store(int64(d)) - s.Interface().Push_tag(`send`, Uinterface{ - Id: 0, //send to all - Data: []byte("ok"), - }) } } } @@ -127,8 +124,6 @@ func Play(filePath string) (s *Server, close func()) { }, }) - sendData := pslice.New[byte]() - for !ctx.Done(sg) { select { case <-timer.C: @@ -141,13 +136,11 @@ func Play(filePath string) (s *Server, close func()) { sendData.Reset() sendData.Append([]byte("[")) for !ctx.Done(sg) { - if data == nil { - if data, e = f.ReadUntil([]byte{'\n'}, 70, humanize.MByte); e != nil && !errors.Is(e, io.EOF) { - panic(e) - } - if len(data) == 0 { - return - } + if data, e = f.ReadUntil([]byte{'\n'}, 70, humanize.MByte); e != nil && !errors.Is(e, io.EOF) { + panic(e) + } + if len(data) == 0 { + return } tIndex := bytes.Index(data, []byte{','}) -- 2.39.2