Files
cc-metric-collector/pkg/multiChanTicker
Holger Obermaier 9908d76aac Cleanup (#197)
* Removed unused code
* Use cclog for logging
* Wrap errors so that they can be unwrapped
* Revert wrong use of slices.Delete()
* Fix derivative values should be float
* Suggestions from the gocritic linter
* Fixed: interface method AddChannel must have all named params (inamedparam)
* Enable linter: errorlint
* Replace fmt.Sprintf("%d", i)) by strconv.Itoa(i) for improved performance
* Correct misspelled words
* Break up very long lines into multiple lines
* lp.NewMessage -> lp.NewMetric
* Preallocate slices of known length
2026-02-13 09:36:14 +01:00
..
2026-02-13 09:36:14 +01:00

MultiChanTicker

The idea of this ticker is to multiply the output channels. The original Golang time.Ticker provides only a single output channel, so the signal can only be received by a single other class. This ticker allows to add multiple channels which get all notified about the time tick.

type MultiChanTicker interface {
	Init(duration time.Duration)
	AddChannel(chan time.Time)
}

The MultiChanTicker is created similarly to the common time.Ticker:

NewTicker(duration time.Duration) MultiChanTicker

Afterwards, you can add channels:

t := MultiChanTicker(duration)
c1 := make(chan time.Time)
c2 := make(chan time.Time)
t.AddChannel(c1)
t.AddChannel(c2)

for {
    select {
    case t1 := <- c1:
        log.Print(t1)
    case t2 := <- c2:
        log.Print(t2)
    }
}

The result should be the same time.Time output in both channels, notified "simultaneously".