Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@emretanriverdi
Created January 17, 2021 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emretanriverdi/5f91cd12ffe2b8d19488e31583c4e2ea to your computer and use it in GitHub Desktop.
Save emretanriverdi/5f91cd12ffe2b8d19488e31583c4e2ea to your computer and use it in GitHub Desktop.
select-channel-fixed.go
func main() {
c1 := make(chan string)
c2 := make(chan string)
go invalidateCrucial(c1)
go invalidateNotSoCruical(c2)
for {
select {
case message5 := <-c1:
fmt.Println(message5)
case message30 := <-c2:
fmt.Println(message30)
}
}
}
func invalidateCrucial(c chan string) {
for {
time.Sleep(time.Second * 5)
c <- "Every 5sec"
}
}
func invalidateNotSoCruical(c chan string) {
for {
time.Sleep(time.Second * 30)
c <- "Every 30sec"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment