Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Created June 20, 2011 20:27
Show Gist options
  • Save kylelemons/1036496 to your computer and use it in GitHub Desktop.
Save kylelemons/1036496 to your computer and use it in GitHub Desktop.
How to broadcast a message to peers
type neuron struct {
coef float64
input chan *stimulus
output []chan *stimulus
}
func newNeuron(coef float64) *neuron {
n := &neuron{
coef: coef,
input: make(chan *stimulus),
}
go func() {
for stimulus := range n.input {
for _, out := range n.output {
out <- stimulus.mult(coef)
}
}
for _, out := range n.output {
close(out)
}
}()
return n
}
func (n *neuron) stimulates(remote *neuron) {
n.output = append(n.output, remote.input)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment