cc-metric-collector/pkg/multiChanTicker
Thomas Gruber be20f956c2
Add latest development to main branch (#89)
* InfiniBandCollector: Scale raw readings from octets to bytes

* Fix clock frequency coming from LikwidCollector and update docs

* Build DEB package for Ubuntu 20.04 for releases

* Fix memstat collector with numa_stats option

* Remove useless prints from MemstatCollector

* Replace ioutils with os and io (#87)

* Use lower case for error strings in RocmSmiCollector

* move maybe-usable-by-other-cc-components to pkg. Fix all files to use the new paths (#88)

* Add collector for monitoring the execution of cc-metric-collector itself (#81)

* Add collector to monitor execution of cc-metric-collector itself

* Register SelfCollector

* Fix import paths for moved packages
2022-10-10 12:23:51 +02:00
..
multiChanTicker.go Add latest development to main branch (#89) 2022-10-10 12:23:51 +02:00
README.md Add latest development to main branch (#89) 2022-10-10 12:23:51 +02: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".