1
0

Listeners struct was renamed to ListenerCounter.

This commit is contained in:
Alexander Andreev 2023-10-01 20:32:07 +04:00
parent dc3658d6de
commit dea283df27
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 12 additions and 12 deletions

View File

@ -37,7 +37,7 @@ func main() {
r := httpr.New()
lstnrs := radio.NewListeners()
lstnrs := radio.NewListenerCounter()
plylst, err := radio.NewPlaylist(*playlist, true)
if err != nil {
log.Fatalln(err)

View File

@ -14,11 +14,11 @@ import (
var songList radio.SongList
type DJHandlers struct {
listeners *radio.Listeners
listeners *radio.ListenerCounter
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)
return &DJHandlers{listeners: l, playlist: p}
}

View File

@ -7,33 +7,33 @@ import (
"sync"
)
// Listeners stores the current and peak numbers of listeners.
type Listeners struct {
// ListenerCounter stores the current and peak numbers of listeners.
type ListenerCounter struct {
mut sync.Mutex
current, peak int
}
// NewListeners returns a new Listeners struct instance.
func NewListeners() *Listeners {
return &Listeners{}
// NewListenerCounter returns a new ListenerCounter struct instance.
func NewListenerCounter() *ListenerCounter {
return &ListenerCounter{}
}
// Current returns a number of current listeners.
func (l *Listeners) Current() int {
func (l *ListenerCounter) Current() int {
l.mut.Lock()
defer l.mut.Unlock()
return l.current
}
// Current returns a number of peak listeners.
func (l *Listeners) Peak() int {
func (l *ListenerCounter) Peak() int {
l.mut.Lock()
defer l.mut.Unlock()
return l.peak
}
// 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()
defer l.mut.Unlock()
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
// a resulting number is less than 0.
func (l *Listeners) Dec() (int, error) {
func (l *ListenerCounter) Dec() (int, error) {
l.mut.Lock()
defer l.mut.Unlock()
if l.current == 0 {