From a330ea6e7fc9d7376980c8b64e383057243094a4 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Tue, 12 Dec 2023 20:59:01 +0100 Subject: [PATCH] Stop all processes in parallel for fast shutdown --- restream/restream.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/restream/restream.go b/restream/restream.go index 031f825b..92379942 100644 --- a/restream/restream.go +++ b/restream/restream.go @@ -251,11 +251,24 @@ func (r *restream) Stop() { // Stop the currently running processes without altering their order such that on a subsequent // Start() they will get restarted. - for id, t := range r.tasks { - if t.ffmpeg != nil { - t.ffmpeg.Stop(true) + + wg := sync.WaitGroup{} + + for _, t := range r.tasks { + if t.ffmpeg == nil { + continue } + wg.Add(1) + go func(p process.Process) { + defer wg.Done() + p.Stop(true) + }(t.ffmpeg) + } + + wg.Wait() + + for id := range r.tasks { r.unsetCleanup(id) }