-
-
Save emretanriverdi/5f91cd12ffe2b8d19488e31583c4e2ea to your computer and use it in GitHub Desktop.
select-channel-fixed.go
This file contains 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
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