Esempio n. 1
0
func dispatch(valueLists []api.ValueList, d api.Writer) {
	for _, vl := range valueLists {
		if err := d.Write(vl); err != nil {
			log.Printf("error while dispatching: %v", err)
		}
	}
}
Esempio n. 2
0
func dispatch(ctx context.Context, valueLists []*api.ValueList, d api.Writer) {
	for _, vl := range valueLists {
		if err := d.Write(ctx, vl); err != nil {
			log.Printf("error while dispatching: %v", err)
		}
	}
}
Esempio n. 3
0
// Run periodically calls the ValueList function of each Var, sets the Time and
// Interval fields and passes it w.Write(). This function blocks indefinitely.
func Run(w api.Writer, opts Options) error {
	ticker := time.NewTicker(opts.Interval)

	for {
		select {
		case _ = <-ticker.C:
			mutex.RLock()
			for _, v := range vars {
				vl := v.ValueList()
				vl.Time = time.Now()
				vl.Interval = opts.Interval
				if err := w.Write(vl); err != nil {
					mutex.RUnlock()
					return err
				}
			}
			mutex.RUnlock()
		}
	}
}