Skip to content

Instantly share code, notes, and snippets.

@ironsmile
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save ironsmile/52ab6202fc99b56310c7 to your computer and use it in GitHub Desktop.

Select an option

Save ironsmile/52ab6202fc99b56310c7 to your computer and use it in GitHub Desktop.
ranging over channel after selecting from it
for {
select {
case elem := <-a.traffChan:
a.aggregateTraff(elem.header, elem.body)
//!TODO maybe return elem to the pool
case elem := <-a.hitChan:
a.aggregateHit(elem.header, elem.body)
//!TODO maybe return elem to the pool
case <-a.stopChan:
close(a.traffChan)
for elem := range a.traffChan {
a.aggregateTraff(elem.header, elem.body)
}
close(a.hitChan)
for elem := range a.hitChan {
a.aggregateHit(elem.header, elem.body)
}
a.aggregationStopped <- struct{}{}
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment