Skip to content

Commit 6189e02

Browse files
committed
refactor: add file process pool constructor
1 parent 33a40a0 commit 6189e02

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

main.go

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ type FileProcessPool struct {
4444
numberOfWorkers int
4545
}
4646

47+
func NewFileProcessPool(numberOfWorkers int, executor func(f File)) *FileProcessPool {
48+
return &FileProcessPool{
49+
tasks: make(chan File),
50+
executor: executor,
51+
wg: new(sync.WaitGroup),
52+
numberOfWorkers: numberOfWorkers,
53+
}
54+
}
55+
4756
func (f *FileProcessPool) Start() {
4857
f.wg.Add(f.numberOfWorkers)
4958
for i := 0; i < f.numberOfWorkers; i++ {

main_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"io"
99
"io/fs"
1010
"os"
11-
"sync"
1211
"testing"
1312
"time"
1413

@@ -147,7 +146,7 @@ func TestFileProcessPool(t *testing.T) {
147146
output.WriteString("hello, world!")
148147
}
149148

150-
fileProcessPool := &FileProcessPool{tasks: make(chan File), executor: executor, wg: new(sync.WaitGroup), numberOfWorkers: 1}
149+
fileProcessPool := NewFileProcessPool(1, executor)
151150
fileProcessPool.Start()
152151

153152
info := getFileInfo(t, helloTxtFileFixture)

0 commit comments

Comments
 (0)