Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.91 KB | None | 0 0
  1. // Process the measuring points.
  2. func MeasuringPointsDo(f func(*MeasuringPoint)) {
  3.     // Get a channel with the measuring points.
  4.  
  5.     outChan := make(chan *MeasuringPoint)
  6.  
  7.     measuringPointOutChanChan <- outChan
  8.  
  9.     // Process the points.
  10.  
  11.     for mp := range outChan {
  12.         f(mp)
  13.     }
  14. }
  15.  
  16.  
  17.  
  18. // The measuring backend goroutine.
  19. func etmBackend() {
  20.     measurings := make(map[string]*MeasuringPoint)
  21.  
  22.     for {
  23.         select {
  24.         case measuring := <-measuringInChan:
  25.             // Received a new measuring.
  26.             if mp, ok := measurings[measuring.id]; ok {
  27.                 // Measuring point found.
  28.                 mp.update(measuring)
  29.  
  30.                 measurings[measuring.id] = mp
  31.             } else {
  32.                 // New measuring point.
  33.                 measurings[measuring.id] = newMeasuringPoint(measuring)
  34.             }
  35.         case outChan := <-measuringPointOutChanChan:
  36.             // Retrieve the measuring points.
  37.             go func() {
  38.                 for _, mp := range measurings {
  39.                     outChan <- mp
  40.                 }
  41.             }()
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement