func (s *WriterSender) Close() error {
	s.mu.Lock()
	defer s.mu.Unlock()
	if err := s.writer.Flush(); err != nil {
		return err
	}
	s.Send(message.NewBytesMessage(s.priority, bytes.TrimRightFunc(s.buffer.Bytes(), unicode.IsSpace)))
	s.buffer.Reset()
	s.writer.Reset(s.buffer)
	return nil
}
Close writes any buffered messages to the underlying Sender. This does
not close the underlying sender.
package send
import (
	"bufio"
	"bytes"
	"io"
	"sync"
	"unicode"
	"github.com/mongodb/grip/level"
	"github.com/mongodb/grip/message"
)
type WriterSender struct {
	Sender
	writer   *bufio.Writer
	buffer   *bytes.Buffer
	priority level.Priority
	mu       sync.Mutex
}
func NewWriterSender(s Sender) *WriterSender { return MakeWriterSender(s, s.Level().Default) }
func MakeWriterSender(s Sender, p level.Priority) *WriterSender {
	buffer := new(bytes.Buffer)
	return &WriterSender{
		Sender:   s,
		priority: p,
		writer:   bufio.NewWriter(buffer),
		buffer:   buffer,
	}
}
func (s *WriterSender) Write(p []byte) (int, error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	n, err := s.writer.Write(p)
	if err != nil {
		return n, err
	}
	_ = s.writer.Flush()
	if s.buffer.Len() > 80 {
		err = s.doSend()
	}
	return n, err
}
func (s *WriterSender) doSend() error {
	for {
		line, err := s.buffer.ReadBytes('\n')
		if err == io.EOF {
			s.buffer.Write(line)
			return nil
		}
		lncp := make([]byte, len(line))
		copy(lncp, line)
		if err == nil {
			s.Send(message.NewBytesMessage(s.priority, bytes.TrimRightFunc(lncp, unicode.IsSpace)))
			continue
		}
		s.Send(message.NewBytesMessage(s.priority, bytes.TrimRightFunc(lncp, unicode.IsSpace)))
		return err
	}
}