Skip to content

Instantly share code, notes, and snippets.

@blakesmith
Created October 8, 2012 21:49
Show Gist options
  • Save blakesmith/3855231 to your computer and use it in GitHub Desktop.
Save blakesmith/3855231 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func intervalMessage(msg string, dur time.Duration) chan string {
outc := make(chan string)
go func() {
for {
time.Sleep(dur)
outc <- msg
}
}()
return outc
}
func main() {
chan1 := intervalMessage("HAHA", 1*time.Second)
chan2 := intervalMessage("LOLZ", 2*time.Second)
for {
select {
case resp := <- chan1:
fmt.Println(resp)
case resp := <- chan2:
fmt.Println(resp)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment