]> 127.0.0.1 Git - part/.git/commitdiff
fix v0.10.3
authorqydysky <32743305+qydysky@users.noreply.github.com>
Sat, 15 Oct 2022 19:20:09 +0000 (03:20 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Sat, 15 Oct 2022 19:20:09 +0000 (03:20 +0800)
websocket/Recoder.go
websocket/Server_test.go

index 0faf4272aa1c0ed8d4aa2499409a5098eee8f4b8..c09efd906a08ddb2e855cdac6435fb48fdfc99bc 100644 (file)
@@ -55,6 +55,10 @@ func (t *Recorder) Start(filePath string) error {
                                }
                                return false
                        },
+                       `close`: func(data interface{}) bool {
+                               t.Stop()
+                               return true
+                       },
                })
                t.stopflag.Wait()
        }()
@@ -68,9 +72,19 @@ func (t *Recorder) Stop() {
        t.onlyOnce.UnSet()
 }
 
-func Play(filePath string, perReadSize int, maxReadSize int) (s *Server) {
+func Play(filePath string, perReadSize int, maxReadSize int) (s *Server, close func()) {
+       sg := signal.Init()
+
        s = New_server()
 
+       close = func() {
+               s.Interface().Push_tag(`close`, uinterface{
+                       Id:   0,
+                       Data: `rev_close`,
+               })
+               sg.Done()
+       }
+
        go func() {
                f := file.New(filePath, 0, false)
                defer f.Close()
@@ -78,10 +92,10 @@ func Play(filePath string, perReadSize int, maxReadSize int) (s *Server) {
                startT := time.Now()
                timer := time.NewTicker(time.Second)
 
-               for {
+               for sg.Islive() {
                        cu := (<-timer.C).Sub(startT).Seconds()
 
-                       for {
+                       for sg.Islive() {
                                if data, err := f.ReadUntil('\n', perReadSize, maxReadSize); err != nil {
                                        panic(err)
                                } else if len(data) != 0 {
index ccf3689e44c8a5e95c9fe48d299d2b7c94cec74c..a7ec6816487138f7ce6eb7845ef71031a5f9d479 100644 (file)
@@ -65,7 +65,8 @@ func Test_Server(t *testing.T) {
 }
 
 func Test_Recoder(t *testing.T) {
-       s := Play("l.csv", 50, 5000)
+       s, cf := Play("l.csv", 50, 5000)
+       defer cf()
 
        w := web.Easy_boot()
        open.Run("http://" + w.Server.Addr)