Merge pull request #19498 from mountkin/refactor-jsonfilelog-reader
use pubsub instead of filenotify to follow json logs
This commit is contained in:
commit
3fcb349dba
1 changed files with 9 additions and 3 deletions
|
@ -54,18 +54,24 @@ func (p *Publisher) SubscribeTopic(topic topicFunc) chan interface{} {
|
||||||
// Evict removes the specified subscriber from receiving any more messages.
|
// Evict removes the specified subscriber from receiving any more messages.
|
||||||
func (p *Publisher) Evict(sub chan interface{}) {
|
func (p *Publisher) Evict(sub chan interface{}) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
|
if _, ok := p.subscribers[sub]; ok {
|
||||||
delete(p.subscribers, sub)
|
delete(p.subscribers, sub)
|
||||||
close(sub)
|
close(sub)
|
||||||
|
}
|
||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publish sends the data in v to all subscribers currently registered with the publisher.
|
// Publish sends the data in v to all subscribers currently registered with the publisher.
|
||||||
func (p *Publisher) Publish(v interface{}) {
|
func (p *Publisher) Publish(v interface{}) {
|
||||||
p.m.RLock()
|
p.m.RLock()
|
||||||
|
if len(p.subscribers) == 0 {
|
||||||
|
p.m.RUnlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
for sub, topic := range p.subscribers {
|
for sub, topic := range p.subscribers {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
go p.sendTopic(sub, topic, v, wg)
|
go p.sendTopic(sub, topic, v, wg)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
Loading…
Reference in a new issue