Listeners struct was renamed to ListenerCounter.
This commit is contained in:
parent
dc3658d6de
commit
dea283df27
@ -37,7 +37,7 @@ func main() {
|
|||||||
|
|
||||||
r := httpr.New()
|
r := httpr.New()
|
||||||
|
|
||||||
lstnrs := radio.NewListeners()
|
lstnrs := radio.NewListenerCounter()
|
||||||
plylst, err := radio.NewPlaylist(*playlist, true)
|
plylst, err := radio.NewPlaylist(*playlist, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
@ -14,11 +14,11 @@ import (
|
|||||||
var songList radio.SongList
|
var songList radio.SongList
|
||||||
|
|
||||||
type DJHandlers struct {
|
type DJHandlers struct {
|
||||||
listeners *radio.Listeners
|
listeners *radio.ListenerCounter
|
||||||
playlist *radio.Playlist
|
playlist *radio.Playlist
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDJHandlers(l *radio.Listeners, p *radio.Playlist, slLen int) *DJHandlers {
|
func NewDJHandlers(l *radio.ListenerCounter, p *radio.Playlist, slLen int) *DJHandlers {
|
||||||
songList = *radio.NewSongList(slLen)
|
songList = *radio.NewSongList(slLen)
|
||||||
return &DJHandlers{listeners: l, playlist: p}
|
return &DJHandlers{listeners: l, playlist: p}
|
||||||
}
|
}
|
||||||
|
@ -7,33 +7,33 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Listeners stores the current and peak numbers of listeners.
|
// ListenerCounter stores the current and peak numbers of listeners.
|
||||||
type Listeners struct {
|
type ListenerCounter struct {
|
||||||
mut sync.Mutex
|
mut sync.Mutex
|
||||||
current, peak int
|
current, peak int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewListeners returns a new Listeners struct instance.
|
// NewListenerCounter returns a new ListenerCounter struct instance.
|
||||||
func NewListeners() *Listeners {
|
func NewListenerCounter() *ListenerCounter {
|
||||||
return &Listeners{}
|
return &ListenerCounter{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current returns a number of current listeners.
|
// Current returns a number of current listeners.
|
||||||
func (l *Listeners) Current() int {
|
func (l *ListenerCounter) Current() int {
|
||||||
l.mut.Lock()
|
l.mut.Lock()
|
||||||
defer l.mut.Unlock()
|
defer l.mut.Unlock()
|
||||||
return l.current
|
return l.current
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current returns a number of peak listeners.
|
// Current returns a number of peak listeners.
|
||||||
func (l *Listeners) Peak() int {
|
func (l *ListenerCounter) Peak() int {
|
||||||
l.mut.Lock()
|
l.mut.Lock()
|
||||||
defer l.mut.Unlock()
|
defer l.mut.Unlock()
|
||||||
return l.peak
|
return l.peak
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inc increments by 1 a current number of listeners and updates a peak number.
|
// Inc increments by 1 a current number of listeners and updates a peak number.
|
||||||
func (l *Listeners) Inc() int {
|
func (l *ListenerCounter) Inc() int {
|
||||||
l.mut.Lock()
|
l.mut.Lock()
|
||||||
defer l.mut.Unlock()
|
defer l.mut.Unlock()
|
||||||
if l.current == math.MaxInt {
|
if l.current == math.MaxInt {
|
||||||
@ -49,7 +49,7 @@ func (l *Listeners) Inc() int {
|
|||||||
|
|
||||||
// Dec decrements by 1 a current number of listeners. An error will occur if
|
// Dec decrements by 1 a current number of listeners. An error will occur if
|
||||||
// a resulting number is less than 0.
|
// a resulting number is less than 0.
|
||||||
func (l *Listeners) Dec() (int, error) {
|
func (l *ListenerCounter) Dec() (int, error) {
|
||||||
l.mut.Lock()
|
l.mut.Lock()
|
||||||
defer l.mut.Unlock()
|
defer l.mut.Unlock()
|
||||||
if l.current == 0 {
|
if l.current == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user