Skip to content

Instantly share code, notes, and snippets.

@brydavis
Created August 19, 2016 18:09
Show Gist options
  • Select an option

  • Save brydavis/a6544c968e2ecd37e2d679ada57d8dec to your computer and use it in GitHub Desktop.

Select an option

Save brydavis/a6544c968e2ecd37e2d679ada57d8dec to your computer and use it in GitHub Desktop.
package main
import (
"container/ring"
"fmt"
"os"
"time"
)
func main() {
Example()
}
func Example() {
coffee := [][]string{
[]string{"kenya", "guatemala", "ethiopia"},
[]string{"abc", "mno", "xyz"},
[]string{"LAX", "SEA", "NYC"},
}
// create a ring and populate it with some values
r := ring.New(len(coffee))
for i := 0; i < r.Len(); i++ {
r.Value = coffee[i]
r = r.Next()
}
// print all values of the ring, easy done with ring.Do()
// end after 10s otherwise play.golang.org gives an error
go func() {
time.Sleep(time.Second * 10)
fmt.Println("-- exiting --")
os.Exit(0)
}()
// .. or each one by one.
for _ = range time.Tick(time.Second * 1) {
r = r.Next()
fmt.Println(r.Value.([]string)[0])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment