func (f *Feed) Send(value interface{}) (nsent int) {
	rvalue := reflect.ValueOf(value)

	f.once.Do(f.init)
	<-f.sendLock

	// Add new cases from the inbox after taking the send lock.
	f.mu.Lock()
	f.sendCases = append(f.sendCases, f.inbox...)
	f.inbox = nil

	if !f.typecheck(rvalue.Type()) {
		f.sendLock <- struct{}{}
		panic(feedTypeError{op: "Send", got: rvalue.Type(), want: f.etype})
	}
	f.mu.Unlock()

	// Set the sent value on all channels.
	for i := firstSubSendCase; i < len(f.sendCases); i++ {
		f.sendCases[i].Send = rvalue
	}

	// Send until all channels except removeSub have been chosen. 'cases' tracks a prefix
	// of sendCases. When a send succeeds, the corresponding case moves to the end of
	// 'cases' and it shrinks by one element.
	cases := f.sendCases
	for {
		// Fast path: try sending without blocking before adding to the select set.
		// This should usually succeed if subscribers are fast enough and have free
		// buffer space.
		for i := firstSubSendCase; i < len(cases); i++ {
			if cases[i].Chan.TrySend(rvalue) {
				nsent++
				cases = cases.deactivate(i)
				i--
			}
		}
		if len(cases) == firstSubSendCase {
			break
		}
		// Select on all the receivers, waiting for them to unblock.
		chosen, recv, _ := reflect.Select(cases)
		if chosen == 0 /* <-f.removeSub */ {
			index := f.sendCases.find(recv.Interface())
			f.sendCases = f.sendCases.delete(index)
			if index >= 0 && index < len(cases) {
				// Shrink 'cases' too because the removed case was still active.
				cases = f.sendCases[:len(cases)-1]
			}
		} else {
			cases = cases.deactivate(chosen)
			nsent++
		}
	}

	// Forget about the sent value and hand off the send lock.
	for i := firstSubSendCase; i < len(f.sendCases); i++ {
		f.sendCases[i].Send = reflect.Value{}
	}
	f.sendLock <- struct{}{}
	return nsent
}
// Send delivers to all subscribed channels simultaneously.
// It returns the number of subscribers that the value was sent to.
Send delivers to all subscribed channels simultaneously.
It returns the number of subscribers that the value was sent to.
// Send delivers to all subscribed channels simultaneously . // It returns the number of subscribers that the value was sent to .
func (f *Feed) Send(value interface{}) (nsent int) {
	rvalue := reflect.ValueOf(value)
	f.once.Do(f.init)
	<-f.sendLock
	f.mu.Lock()
	f.sendCases = append(f.sendCases, f.inbox...)
	f.inbox = nil
	if !f.typecheck(rvalue.Type()) {
		f.sendLock <- struct{}{}
		panic(feedTypeError{op: "Send", got: rvalue.Type(), want: f.etype})
	}
	f.mu.Unlock()
	for i := firstSubSendCase; i < len(f.sendCases); i++ {
		f.sendCases[i].Send = rvalue
	}
	cases := f.sendCases
	for {
		for i := firstSubSendCase; i < len(cases); i++ {
			if cases[i].Chan.TrySend(rvalue) {
				nsent++
				cases = cases.deactivate(i)
				i--
			}
		}
		if len(cases) == firstSubSendCase {
			break
		}
		chosen, recv, _ := reflect.Select(cases)
		if chosen == 0  {
			index := f.sendCases.find(recv.Interface())
			f.sendCases = f.sendCases.delete(index)
			if index >= 0 && index < len(cases) {
				cases = f.sendCases[:len(cases)-1]
			}
		} else {
			cases = cases.deactivate(chosen)
			nsent++
		}
	}
	for i := firstSubSendCase; i < len(f.sendCases); i++ {
		f.sendCases[i].Send = reflect.Value{}
	}
	f.sendLock <- struct{}{}
	return nsent
}
func ( f * Feed ) Send ( value interface { } ) ( nsent int ) { rvalue := reflect . ValueOf ( value ) f . once . Do ( f . init ) <- f . sendLock f . mu . Lock ( ) f . sendCases = append ( f . sendCases , f . inbox ... ) f . inbox = nil if ! f . typecheck ( rvalue . Type ( ) ) { f . sendLock <- struct { } { } panic ( feedTypeError { op : " " , got : rvalue . Type ( ) , want : f . etype } ) } f . mu . Unlock ( ) for i := firstSubSendCase ; i < len ( f . sendCases ) ; i ++ { f . sendCases [ i ] . Send = rvalue } cases := f . sendCases for { for i := firstSubSendCase ; i < len ( cases ) ; i ++ { if cases [ i ] . Chan . TrySend ( rvalue ) { nsent ++ cases = cases . deactivate ( i ) i -- } } if len ( cases ) == firstSubSendCase { break } chosen , recv , _ := reflect . Select ( cases ) if chosen == 0 { index := f . sendCases . find ( recv . Interface ( ) ) f . sendCases = f . sendCases . delete ( index ) if index >= 0 && index < len ( cases ) { cases = f . sendCases [ : len ( cases ) - 1 ] } } else { cases = cases . deactivate ( chosen ) nsent ++ } } for i := firstSubSendCase ; i < len ( f . sendCases ) ; i ++ { f . sendCases [ i ] . Send = reflect . Value { } } f . sendLock <- struct { } { } return nsent }
Send delivers to all subscribed channels simultaneously.
Send delivers to all subscribed channels simultaneously .
// Add new cases from the inbox after taking the send lock. // Set the sent value on all channels. // Send until all channels except removeSub have been chosen. 'cases' tracks a prefix // of sendCases. When a send succeeds, the corresponding case moves to the end of // 'cases' and it shrinks by one element. // Fast path: try sending without blocking before adding to the select set. // This should usually succeed if subscribers are fast enough and have free // buffer space. // Select on all the receivers, waiting for them to unblock. /* <-f.removeSub */ // Shrink 'cases' too because the removed case was still active. // Forget about the sent value and hand off the send lock.