From: qydysky Date: Thu, 30 Mar 2023 04:15:12 +0000 (+0000) Subject: Improve 录制保存到文件添加context X-Git-Tag: v0.8.0~8^2 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=adf80d981d199358ac0ea73da61df6639239aa70;p=bili_danmu%2F.git Improve 录制保存到文件添加context --- 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