Created
May 9, 2014 03:51
-
-
Save wingyplus/b3f702f0172785f31a9c to your computer and use it in GitHub Desktop.
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
package consensus | |
import "fmt" | |
type Journal struct {} | |
func (journal Journal) Write(msg string) { | |
} | |
func GetConsensus(journal Journal) boolean { | |
size := 3 | |
answers := make(chan bool, size) | |
for i := 0 ; i < size ; i++ { | |
go func() { | |
answer := GetRandomAnswer() | |
answers <- answer | |
journal.Write(fmt.Sprintf("Node %d answer: %s", i, answer)) | |
}() | |
} | |
trueCount := 0 | |
for answer := range answer { | |
if answer == true { | |
trueCount++ | |
} | |
} | |
result := trueCount > 2 | |
journal.Write(fmt.Sprintf("Consensus: %v", result)) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment