From 57fa6a55309fb80ab03d50c2a573df45cd20f029 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Sun, 8 Jan 2023 20:31:00 +0300 Subject: [PATCH] Add support for simultaneous requests from different consumers --- cmd/streams/stream.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/streams/stream.go b/cmd/streams/stream.go index ac998cb5..ce44e40a 100644 --- a/cmd/streams/stream.go +++ b/cmd/streams/stream.go @@ -18,6 +18,7 @@ type Stream struct { producers []*Producer consumers []*Consumer mu sync.Mutex + wg sync.WaitGroup } func NewStream(source interface{}) *Stream { @@ -59,6 +60,9 @@ func (s *Stream) AddConsumer(cons streamer.Consumer) (err error) { var codecs string + // support for multiple simultaneous requests from different consumers + s.wg.Add(1) + // Step 1. Get consumer medias for icc, consMedia := range cons.GetMedias() { log.Trace().Stringer("media", consMedia). @@ -97,6 +101,9 @@ func (s *Stream) AddConsumer(cons streamer.Consumer) (err error) { } } + s.wg.Done() + s.wg.Wait() + if len(producers) == 0 { s.stopProducers()