Skip to content

Instantly share code, notes, and snippets.

@monkeybutter
Created August 4, 2016 20:45
Show Gist options
  • Select an option

  • Save monkeybutter/17ad5bb6804d32dcd8b8d93a79c1232c to your computer and use it in GitHub Desktop.

Select an option

Save monkeybutter/17ad5bb6804d32dcd8b8d93a79c1232c to your computer and use it in GitHub Desktop.
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