Last active
February 15, 2018 12:12
-
-
Save WhisperingChaos/0969b37a2586d14713a2afb42bbc50bf to your computer and use it in GitHub Desktop.
Nil Channel favor/bias channels:
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
func consumeAccordingToChannelSemantics(msg_1ch chan msg_1, msg_2ch chan msg_2) { | |
// because the channels were asychronous and completely full | |
// before running this routine, select's channel semantics | |
// considers the messages as having arrived at the same time. | |
// select therefore randomly reads one of the channels. since | |
// only two case statements, probability of selection is | |
// equivalent to a random coin toss. | |
for msgCnt := 0; msgCnt < 21; msgCnt++ { | |
select { | |
case msg, ok := <-msg_1ch: | |
if ok { | |
msg.msgType() | |
} | |
case msg, ok := <-msg_2ch: | |
if ok { | |
msg.msgType() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment