Formatting

This commit is contained in:
Thomas Roehl
2021-12-21 14:04:31 +01:00
parent 988cea381e
commit a6feb16ec1
30 changed files with 775 additions and 793 deletions

View File

@@ -1,39 +1,39 @@
package multiChanTicker
import (
"time"
"time"
)
type multiChanTicker struct {
ticker *time.Ticker
channels []chan time.Time
ticker *time.Ticker
channels []chan time.Time
}
type MultiChanTicker interface {
Init(duration time.Duration)
AddChannel(chan time.Time)
Init(duration time.Duration)
AddChannel(chan time.Time)
}
func (t *multiChanTicker) Init(duration time.Duration) {
t.ticker = time.NewTicker(duration)
go func() {
for {
select {
case ts := <-t.ticker.C:
for _, c := range t.channels {
c <- ts
}
}
}
}()
t.ticker = time.NewTicker(duration)
go func() {
for {
select {
case ts := <-t.ticker.C:
for _, c := range t.channels {
c <- ts
}
}
}
}()
}
func (t *multiChanTicker) AddChannel(channel chan time.Time) {
t.channels = append(t.channels, channel)
t.channels = append(t.channels, channel)
}
func NewTicker(duration time.Duration) MultiChanTicker {
t := &multiChanTicker{}
t.Init(duration)
return t
t := &multiChanTicker{}
t.Init(duration)
return t
}