func (b *InjectionStreamer) Flush() (s *InjectionStreamer, err error) {
	r, size := b.head.ReverseList()
	batch := ListToArrayOfInjectionReads(r, size)
	if len(batch) > 0 {
		innerWriter, err := b.wr.WriteInjectionBatch(batch)
		if err != nil {
			return nil, err
		} else {
			return newInjectionStreamerDuration(nil, nil, innerWriter, b.d), nil
		}
	}
	return newInjectionStreamerDuration(nil, nil, b.wr, b.d), nil
}
Flush writes any buffered data to the underlying glukitio.Writer as a batch.
package streaming
import (
	"github.com/alexandre-normand/glukit/app/apimodel"
	"github.com/alexandre-normand/glukit/app/container"
	"github.com/alexandre-normand/glukit/app/glukitio"
	"time"
)
type InjectionStreamer struct {
	head      *container.ImmutableList
	startTime *time.Time
	wr        glukitio.InjectionBatchWriter
	d         time.Duration
}
func NewInjectionStreamerDuration(wr glukitio.InjectionBatchWriter, bufferDuration time.Duration) *InjectionStreamer {
	return newInjectionStreamerDuration(nil, nil, wr, bufferDuration)
}
func newInjectionStreamerDuration(head *container.ImmutableList, startTime *time.Time, wr glukitio.InjectionBatchWriter, bufferDuration time.Duration) *InjectionStreamer {
	w := new(InjectionStreamer)
	w.head = head
	w.startTime = startTime
	w.wr = wr
	w.d = bufferDuration
	return w
}
func (b *InjectionStreamer) WriteInjection(c apimodel.Injection) (s *InjectionStreamer, err error) {
	return b.WriteInjections([]apimodel.Injection{c})
}
func (b *InjectionStreamer) WriteInjections(p []apimodel.Injection) (s *InjectionStreamer, err error) {
	s = newInjectionStreamerDuration(b.head, b.startTime, b.wr, b.d)
	if err != nil {
		return s, err
	}
	for i := range p {
		c := p[i]
		t := c.GetTime()
		truncatedTime := t.Truncate(s.d)
		if s.head == nil {
			s = newInjectionStreamerDuration(container.NewImmutableList(nil, c), &truncatedTime, s.wr, s.d)
		} else if t.Sub(*s.startTime) >= s.d {
			s, err = s.Flush()
			if err != nil {
				return s, err
			}
			s = newInjectionStreamerDuration(container.NewImmutableList(nil, c), &truncatedTime, s.wr, s.d)
		} else {
			s = newInjectionStreamerDuration(container.NewImmutableList(s.head, c), s.startTime, s.wr, s.d)
		}
	}
	return s, err
}