Skip to content

Commit 98d2a09

Browse files
committed
Introduce GoPool interface and update NewGoPool function
- Introduced a new GoPool interface that includes all public methods of the goPool struct. - Updated the NewGoPool function to return the GoPool interface instead of the goPool struct. - This change makes the GoPool interface visible outside the package and allows for future extensions with different GoPool implementations. Signed-off-by: Daniel Hu <tao.hu@merico.dev>
1 parent 2ea0ed3 commit 98d2a09

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

gopool.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import (
66
"time"
77
)
88

9+
// GoPool represents a pool of workers.
10+
type GoPool interface {
11+
AddTask(t task)
12+
Wait()
13+
Release()
14+
}
15+
916
// task represents a function that will be executed by a worker.
1017
// It returns a result and an error.
1118
type task func() (interface{}, error)
@@ -37,7 +44,7 @@ type goPool struct {
3744
}
3845

3946
// NewGoPool creates a new pool of workers.
40-
func NewGoPool(maxWorkers int, opts ...Option) *goPool {
47+
func NewGoPool(maxWorkers int, opts ...Option) GoPool {
4148
ctx, cancel := context.WithCancel(context.Background())
4249
pool := &goPool{
4350
maxWorkers: maxWorkers,

worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (w *worker) executeTaskWithTimeout(t task, pool *goPool) (result interface{
6969
return result, err
7070
case <-ctx.Done():
7171
// The context timed out, the task took too long
72-
return nil, fmt.Errorf("Task timed out")
72+
return nil, fmt.Errorf("task timed out")
7373
}
7474
}
7575

0 commit comments

Comments
 (0)