From adf80d981d199358ac0ea73da61df6639239aa70 Mon Sep 17 00:00:00 2001 From: qydysky Date: Thu, 30 Mar 2023 04:15:12 +0000 Subject: [PATCH] =?utf8?q?Improve=20=E5=BD=95=E5=88=B6=E4=BF=9D=E5=AD=98?= =?utf8?q?=E5=88=B0=E6=96=87=E4=BB=B6=E6=B7=BB=E5=8A=A0context?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/stream.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Reply/stream.go b/Reply/stream.go index 307311b..88d7ef8 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -1255,7 +1255,7 @@ func (t *M4SStream) Stop() { // 保存到文件 // filepath: 不包含后缀,会自动添加后缀 -func (t *M4SStream) PusherToFile(filepath string, startFunc func(*M4SStream) error, stopFunc func(*M4SStream) error) error { +func (t *M4SStream) PusherToFile(cont context.Context, filepath string, startFunc func(*M4SStream) error, stopFunc func(*M4SStream) error) error { f := file.New(filepath+"."+t.stream_type, 0, true) if e := f.Delete(); e != nil { return e @@ -1269,9 +1269,14 @@ func (t *M4SStream) PusherToFile(filepath string, startFunc func(*M4SStream) err if len(t.boot_buf) != 0 { f.Write(t.boot_buf, true) } - contextC, cancel := context.WithCancel(context.Background()) + contextC, cancel := context.WithCancel(cont) t.Stream_msg.Pull_tag(map[string]func([]byte) bool{ `data`: func(b []byte) bool { + select { + case <-contextC.Done(): + return true + default: + } if len(b) == 0 { cancel() return true -- 2.39.2