github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/stream/multi_flusher.go (about)

     1  package stream
     2  
     3  // multiFlusher is the Flusher implementation underlying NewMultiFlusher.
     4  type multiFlusher struct {
     5  	// flushers are the underlying flushers.
     6  	flushers []Flusher
     7  }
     8  
     9  // NewMultiFlusher creates a single flusher that flushes multiple underlying
    10  // flushers. The flushers are flushed in the order specified, and thus higher
    11  // layers should be specified before lower. If an error occurs, then flushing
    12  // halts and subsequent flushers are not flushed.
    13  func NewMultiFlusher(flushers ...Flusher) Flusher {
    14  	return &multiFlusher{flushers}
    15  }
    16  
    17  // Flush implements Flusher.Flush.
    18  func (f *multiFlusher) Flush() error {
    19  	for _, flusher := range f.flushers {
    20  		if err := flusher.Flush(); err != nil {
    21  			return err
    22  		}
    23  	}
    24  	return nil
    25  }