Skip to content

Instantly share code, notes, and snippets.

@jeeyoungk
Last active July 7, 2019 01:37
Show Gist options
  • Save jeeyoungk/94ec0129f62fc88ca6b1a2e337d336bc to your computer and use it in GitHub Desktop.
Save jeeyoungk/94ec0129f62fc88ca6b1a2e337d336bc to your computer and use it in GitHub Desktop.
Go - Selecting channels with priorities (solution)
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