Created
August 4, 2016 20:45
-
-
Save monkeybutter/17ad5bb6804d32dcd8b8d93a79c1232c 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 ( | |
| "fmt" | |
| "math/rand" | |
| "time" | |
| ) | |
| func FeedStream(buf chan int, n int) { | |
| time.Sleep(1500 * time.Millisecond) | |
| for i:=0; i<n; i++ { | |
| buf <- rand.Intn(100) | |
| } | |
| } | |
| func main() { | |
| stream := make(chan int, 1000) | |
| go func(){for range time.Tick(1 * time.Second) { | |
| go FeedStream(stream, 100) | |
| }}() | |
| for n := range stream { | |
| fmt.Printf("Received %d\n", n) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment