Created
October 8, 2012 21:49
-
-
Save blakesmith/3855231 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" | |
"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