Skip to content

Instantly share code, notes, and snippets.

@wingyplus
Created May 9, 2014 03:51
Show Gist options
  • Save wingyplus/b3f702f0172785f31a9c to your computer and use it in GitHub Desktop.
Save wingyplus/b3f702f0172785f31a9c to your computer and use it in GitHub Desktop.
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