Last active
July 7, 2019 01:37
-
-
Save jeeyoungk/94ec0129f62fc88ca6b1a2e337d336bc to your computer and use it in GitHub Desktop.
Go - Selecting channels with priorities (solution)
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 SelectWithPriorities(highPri <-chan int, lowPri <-chan int) int { | |
select { | |
case val := <-highPri: | |
return val | |
default: | |
select { | |
case val := <-highPri: | |
return val | |
case val := <-lowPri: | |
return val | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment