mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
stream fix listener counts.
This commit is contained in:
parent
9d4d5766ef
commit
5bb2da2732
@ -100,13 +100,13 @@ func (manager *StreamManagerCtx) NewListener(listener *func(sample types.Sample)
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
||||
if manager.listenersCount == 0 {
|
||||
manager.listenersCount++
|
||||
if manager.listenersCount == 1 {
|
||||
err := manager.createPipeline()
|
||||
if err != nil && !errors.Is(err, types.ErrCapturePipelineAlreadyExists) {
|
||||
return addListener, err
|
||||
}
|
||||
|
||||
manager.listenersCount++
|
||||
manager.logger.Info().Msgf("first listener, starting")
|
||||
}
|
||||
|
||||
@ -134,11 +134,15 @@ func (manager *StreamManagerCtx) RemoveListener(listener *func(sample types.Samp
|
||||
|
||||
manager.logger.Debug().Interface("ptr", ptr).Msgf("removing listener")
|
||||
|
||||
manager.mu.Lock()
|
||||
manager.listenersCount--
|
||||
manager.mu.Unlock()
|
||||
|
||||
go func() {
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
||||
if manager.listenersCount == 1 {
|
||||
if manager.listenersCount == 0 {
|
||||
manager.destroyPipeline()
|
||||
manager.listenersCount = 0
|
||||
manager.logger.Info().Msgf("last listener, stopping")
|
||||
|
Loading…
Reference in New Issue
Block a user