func (m *AsyncLoadBalancerMode) Close() error {
	close(m.done)
	m.wg.Wait()
	return nil
}
Close stops all workers and closes all open connections. In flight events
are signaled as failed.
package mode
import (
	"sync"
	"time"
	"github.com/elastic/beats/libbeat/common"
	"github.com/elastic/beats/libbeat/logp"
	"github.com/elastic/beats/libbeat/outputs"
)
type AsyncLoadBalancerMode struct {
	timeout      time.Duration  
	waitRetry    time.Duration  
	maxWaitRetry time.Duration  
	maxAttempts int
	wg   sync.WaitGroup
	done chan struct{}
	work    chan eventsMessage
	retries chan eventsMessage
}
func NewAsyncLoadBalancerMode(
	clients []AsyncProtocolClient,
	maxAttempts int,
	waitRetry, timeout, maxWaitRetry time.Duration,
) (*AsyncLoadBalancerMode, error) {
	debug("configure maxattempts: %v", maxAttempts)
	if maxAttempts == 0 {
		maxAttempts = -1
	}
	m := &AsyncLoadBalancerMode{
		timeout:      timeout,
		maxWaitRetry: maxWaitRetry,
		waitRetry:    waitRetry,
		maxAttempts:  maxAttempts,
		work:    make(chan eventsMessage),
		retries: make(chan eventsMessage, len(clients)*2),
		done:    make(chan struct{}),
	}
	m.start(clients)
	return m, nil
}