From 9dfc1d305881778baddfcf521e457b425e5bc627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sat, 26 Oct 2024 02:33:18 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20=E5=B0=9D=E8=AF=95=E6=94=B9?= =?UTF-8?q?=E5=96=84=E6=97=A5=E5=BF=97=E6=80=A7=E8=83=BD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5ac43df821ce73af0037b9c1fdc945655c8156b4. --- internal/service/ws.go | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/internal/service/ws.go b/internal/service/ws.go index 140af95e..4cc413e0 100644 --- a/internal/service/ws.go +++ b/internal/service/ws.go @@ -4,9 +4,7 @@ import ( "bufio" "context" "net/http" - "strings" "sync" - "time" "github.com/gorilla/websocket" @@ -103,28 +101,10 @@ func (s *WsService) Exec(w http.ResponseWriter, r *http.Request) { go func() { scanner := bufio.NewScanner(out) - var batch []string - ticker := time.NewTicker(200 * time.Millisecond) - defer ticker.Stop() - - go func() { - for range ticker.C { - if len(batch) > 0 { - _ = ws.WriteMessage(websocket.TextMessage, []byte(strings.Join(batch, "\n"))) - batch = nil - } - } - }() - for scanner.Scan() { line := scanner.Text() - batch = append(batch, line) + _ = ws.WriteMessage(websocket.TextMessage, []byte(line)) } - - if len(batch) > 0 { - _ = ws.WriteMessage(websocket.TextMessage, []byte(strings.Join(batch, "\n"))) - } - if err = scanner.Err(); err != nil { _ = ws.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "failed to read command output")) }