Created
August 19, 2016 18:09
-
-
Save brydavis/a6544c968e2ecd37e2d679ada57d8dec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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