<commit_before>package pool

import (
	log "github.com/Sirupsen/logrus"
	"sync"
)

// Task encapsulates a work item that should go in the pool.
type Task struct {
	err error
	f   func() error
}

// NewTask initializes a new Task based on a given work function.
func NewTask(f func() error) *Task {
	return &Task{f: f}
}

// Run runs a Task and does appropriate accounting via a given sync.WorkGroup.
func (t *Task) Run(wg *sync.WaitGroup) {
	t.err = t.f()
	wg.Done()
}

// Pool is a worker group that runs a number of Task instances at a configured
// concurrency.
type Pool struct {
	concurrency int
	tasks       []*Task
	tasksChan   chan *Task
	wg          *sync.WaitGroup
}

// NewPool initializes a new Pool with the given tasks and at the given
// concurrency.
func NewPool(tasks []*Task, concurrency int) *Pool {
	return &Pool{
		concurrency: concurrency,
		tasks:       tasks,
		tasksChan:   make(chan *Task),
		wg:          new(sync.WaitGroup),
	}
}

// Run runs all work within the Pool. The first error that's detected after all
// work is done is returned.
func (p *Pool) Run() error {
	log.Infof("Running %v task(s) at concurrency %v",
		len(p.tasks), p.concurrency)

	for i := 0; i < p.concurrency; i++ {
		go p.work()
	}

	p.wg.Add(len(p.tasks))
	for _, task := range p.tasks {
		p.tasksChan <- task
	}
	p.wg.Wait()<commit_msg>Correct punctuation + go to debug<commit_after>package pool

import (
	log "github.com/Sirupsen/logrus"
	"sync"
)

// Task encapsulates a work item that should go in the pool.
type Task struct {
	err error
	f   func() error
}

// NewTask initializes a new Task based on a given work function.
func NewTask(f func() error) *Task {
	return &Task{f: f}
}

// Run runs a Task and does appropriate accounting via a given sync.WorkGroup.
func (t *Task) Run(wg *sync.WaitGroup) {
	t.err = t.f()
	wg.Done()
}

// Pool is a worker group that runs a number of Task instances at a configured
// concurrency.
type Pool struct {
	concurrency int
	tasks       []*Task
	tasksChan   chan *Task
	wg          *sync.WaitGroup
}

// NewPool initializes a new Pool with the given tasks and at the given
// concurrency.
func NewPool(tasks []*Task, concurrency int) *Pool {
	return &Pool{
		concurrency: concurrency,
		tasks:       tasks,
		tasksChan:   make(chan *Task),
		wg:          new(sync.WaitGroup),
	}
}

// Run runs all work within the Pool. The first error that's detected after all
// work is done is returned.
func (p *Pool) Run() error {
	log.Debugf("Running %v task(s) at concurrency %v.",
		len(p.tasks), p.concurrency)

	for i := 0; i < p.concurrency; i++ {
		go p.work()
	}

	p.wg.Add(len(p.tasks))
	for _, task := range p.tasks {
		p.tasksChan <- task
	}
	p.wg.Wait()
{'fraction_non_alphanumeric': 0.11834319526627218, 'fraction_numerical': 0.0007396449704142012, 'mean_word_length': 3.055472263868066, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3042379', 'n_tokens_mistral': 968, 'n_tokens_neox': 920, 'n_words': 345}