Remove publisher if no one is listening
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
eff8e3294c
commit
a96214b8c6
1 changed files with 8 additions and 0 deletions
|
@ -26,6 +26,14 @@ type Publisher struct {
|
||||||
subscribers map[subscriber]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.
|
// Subscribe adds a new subscriber to the publisher returning the channel.
|
||||||
func (p *Publisher) Subscribe() chan interface{} {
|
func (p *Publisher) Subscribe() chan interface{} {
|
||||||
ch := make(chan interface{}, p.buffer)
|
ch := make(chan interface{}, p.buffer)
|
||||||
|
|
Loading…
Reference in a new issue