Created
February 15, 2018 03:45
-
-
Save WhisperingChaos/d3547a0e9fe81c5b6004e5f73d622963 to your computer and use it in GitHub Desktop.
Nil Channel favor/prioritize channels: order by bias
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 consumeOrderedByBias(msg_1ch chan msg_1, msg_2ch chan msg_2) { | |
// copy channels to enable their restoration | |
msg_1_save := msg_1ch | |
msg_2_save := msg_2ch | |
// bias function encoded as a for loop | |
for msgCnt := 0; msgCnt < 21; msgCnt++ { | |
// use modulus math to help implement bias function | |
if msgCnt%3 == 0 { | |
// favor channel 1 when processing muliples of 3 | |
msg_1ch = msg_1_save | |
// bias channel 2 | |
msg_2ch = nil | |
} else { | |
// favor channel 2 when not a multiple of 3 | |
msg_2ch = msg_2_save | |
// bias channel 1 | |
msg_1ch = nil | |
} | |
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