func (m *multiWriter) Write(p []byte) (n int, err error) {
	// lock and make a local copy of available writers:
	getWriters := func() (writers []writerWrapper) {
		m.RLock()
		defer m.RUnlock()
		writers = make([]writerWrapper, 0, len(m.writers))
		for _, w := range m.writers {
			writers = append(writers, w)
		}

		// add the recent write chunk to the "instant replay" buffer
		// of the session, to be replayed to newly joining parties:
		m.lockedAddRecentWrite(p)
		return writers
	}

	// unlock and multiplex the write to all writers:
	for _, w := range getWriters() {
		n, err = w.Write(p)
		if err != nil {
			if w.closeOnError {
				return
			}
			continue
		}
		if n != len(p) {
			err = io.ErrShortWrite
			return
		}
	}
	return len(p), nil
}
// Write multiplexes the input to multiple sub-writers. The entire point
// of multiWriter is to do this
Write multiplexes the input to multiple sub-writers. The entire point
of multiWriter is to do this
// Write multiplexes the input to multiple sub - writers . The entire point // of multiWriter is to do this
func (m *multiWriter) Write(p []byte) (n int, err error) {
	getWriters := func() (writers []writerWrapper) {
		m.RLock()
		defer m.RUnlock()
		writers = make([]writerWrapper, 0, len(m.writers))
		for _, w := range m.writers {
			writers = append(writers, w)
		}
		m.lockedAddRecentWrite(p)
		return writers
	}
	for _, w := range getWriters() {
		n, err = w.Write(p)
		if err != nil {
			if w.closeOnError {
				return
			}
			continue
		}
		if n != len(p) {
			err = io.ErrShortWrite
			return
		}
	}
	return len(p), nil
}
func ( m * multiWriter ) Write ( p [ ] byte ) ( n int , err error ) { getWriters := func ( ) ( writers [ ] writerWrapper ) { m . RLock ( ) defer m . RUnlock ( ) writers = make ( [ ] writerWrapper , 0 , len ( m . writers ) ) for _ , w := range m . writers { writers = append ( writers , w ) } m . lockedAddRecentWrite ( p ) return writers } for _ , w := range getWriters ( ) { n , err = w . Write ( p ) if err != nil { if w . closeOnError { return } continue } if n != len ( p ) { err = io . ErrShortWrite return } } return len ( p ) , nil }
Write multiplexes the input to multiple sub-writers.
Write multiplexes the input to multiple sub - writers .
// lock and make a local copy of available writers: // add the recent write chunk to the "instant replay" buffer // of the session, to be replayed to newly joining parties: // unlock and multiplex the write to all writers: