bcast.go
func (g *Group) Broadcast(timeout time.Duration) {
	var timeoutChannel <-chan time.Time
	if timeout != 0 {
		timeoutChannel = time.After(timeout)
	}
	for {
		select {
		case received := <-g.in:
			g.memberLock.Lock()
			g.clockLock.Lock()
			members := g.members[:]
			received.clock = g.clock
			g.clock++
			g.clockLock.Unlock()
			g.memberLock.Unlock()
			for _, member := range members {
				// This is done in a goroutine because if it
				// weren't it would be a blocking call
				go func(member *Member, received Message) {
					member.send <- received
				}(member, received)
			}
		case <-timeoutChannel:
			if timeout > 0 {
				return
			}
		case <-g.close:
			return
		}
	}
}
func (g *Group) Broadcast(timeout time.Duration) {
	var timeoutChannel <-chan time.Time
	if timeout != 0 {
		timeoutChannel = time.After(timeout)
	}
	for {
		select {
		case received := <-g.in:
			g.memberLock.Lock()
			g.clockLock.Lock()
			members := g.members[:]
			received.clock = g.clock
			g.clock++
			g.clockLock.Unlock()
			g.memberLock.Unlock()
			for _, member := range members {
				// This is done in a goroutine because if it
				// weren't it would be a blocking call
				go func(member *Member, received Message) {
					member.send <- received
				}(member, received)
			}
		case <-timeoutChannel:
			if timeout > 0 {
				return
			}
		case <-g.close:
			return
		}
	}
}
func ( g * Group ) Broadcast ( timeout time . Duration ) { var timeoutChannel <- chan time . Time if timeout != 0 { timeoutChannel = time . After ( timeout ) } for { select { case received := <- g . in : g . memberLock . Lock ( ) g . clockLock . Lock ( ) members := g . members [ : ] received . clock = g . clock g . clock ++ g . clockLock . Unlock ( ) g . memberLock . Unlock ( ) for _ , member := range members { // This is done in a goroutine because if it // weren't it would be a blocking call go func ( member * Member , received Message ) { member . send <- received } ( member , received ) } case <- timeoutChannel : if timeout > 0 { return } case <- g . close : return } } }
// Broadcast messages received from one group member to others.
// If incoming messages not arrived during `timeout` then function returns.
Broadcast messages received from one group member to others . If incoming messages not arrived during timeout then function returns .