<commit_before>package broker

import (
	"net"
	"sync"
	"sync/atomic"
	"time"

	"gopkg.in/fatih/pool.v2"
	"h12.me/kpax/model"
)

const defaultTimeout = 30 * time.Second

type PoolBroker struct {
	Timeout time.Duration
	MaxCap  int
	addr    string
	cid     int32

	p  pool.Pool
	mu sync.Mutex
}

func NewPoolBroker(addr string) model.Broker {
	return &PoolBroker{
		addr:    addr,
		MaxCap:  10,
		Timeout: defaultTimeout,
	}
}

func (b *PoolBroker) Do(req model.Request, resp model.Response) error {
	var (
		err error
		p   pool.Pool
	)
	b.mu.Lock()
	if b.p == nil {
		b.p, err = pool.NewChannelPool(0, b.MaxCap, func() (net.Conn, error) {
			return net.DialTimeout("tcp", b.addr, b.Timeout)
		})
	}<commit_msg>return PoolBroker directly<commit_after>package broker

import (
	"net"
	"sync"
	"sync/atomic"
	"time"

	"gopkg.in/fatih/pool.v2"
	"h12.me/kpax/model"
)

const defaultTimeout = 30 * time.Second

type PoolBroker struct {
	Timeout time.Duration
	MaxCap  int
	addr    string
	cid     int32

	p  pool.Pool
	mu sync.Mutex
}

func NewPoolBroker(addr string) *PoolBroker {
	return &PoolBroker{
		addr:    addr,
		MaxCap:  10,
		Timeout: defaultTimeout,
	}
}

func (b *PoolBroker) Do(req model.Request, resp model.Response) error {
	var (
		err error
		p   pool.Pool
	)
	b.mu.Lock()
	if b.p == nil {
		b.p, err = pool.NewChannelPool(0, b.MaxCap, func() (net.Conn, error) {
			return net.DialTimeout("tcp", b.addr, b.Timeout)
		})
	}
{'fraction_non_alphanumeric': 0.1309192200557103, 'fraction_numerical': 0.013927576601671309, 'mean_word_length': 3.226470588235294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2794552', 'n_tokens_mistral': 623, 'n_tokens_neox': 589, 'n_words': 138}