Remove publisher if no one is listening

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Upstream-commit: 217a2bd1b62788e53fd38810b30672db58a4efc5
Component: engine
This commit is contained in:
Michael Crosby
2015-01-20 11:37:50 -08:00
parent a77fb96f4c
commit b793c28c03
3 changed files with 13 additions and 2 deletions

View File

@ -26,6 +26,14 @@ type Publisher struct {
subscribers map[subscriber]struct{}
}
// Len returns the number of subscribers for the publisher
func (p *Publisher) Len() int {
p.m.RLock()
i := len(p.subscribers)
p.m.RUnlock()
return i
}
// Subscribe adds a new subscriber to the publisher returning the channel.
func (p *Publisher) Subscribe() chan interface{} {
ch := make(chan interface{}, p.buffer)