Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added a basic description to the README.md file. - Created a new go.mod file with the module name and Go version. - Implemented the basic structure of the Pool in pool.go. - Implemented the basic structure of the Worker in worker.go. Signed-off-by: Daniel Hu <tao.hu@merico.dev>
- Loading branch information
1 parent
8db7a84
commit b30bc38
Showing
4 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# gopool | ||
# GoPool | ||
|
||
GoPool is a high-performance, feature-rich, and easy-to-use Golang thread pool. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/devchat-ai/gopool | ||
|
||
go 1.20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package gopool | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
type Pool struct { | ||
// capacity represents the maximum number of workers the pool can have | ||
capacity int | ||
// running represents the number of workers that are currently running | ||
running int | ||
// workers represents a pool of workers that are executing tasks | ||
workers WorkerStack | ||
// lock represents a mutex to protect the workers slice | ||
lock sync.Mutex | ||
} | ||
|
||
func (p *Pool) Submit(task Task) { | ||
// TODO | ||
} | ||
|
||
func (p *Pool) Running() int { | ||
return p.running | ||
} | ||
|
||
func (p *Pool) Cap() int { | ||
return p.capacity | ||
} | ||
|
||
func (p *Pool) Release() { | ||
// TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package gopool | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type Task func() | ||
|
||
type Worker struct { | ||
// pool represents a reference to the pool that owns this worker | ||
pool *Pool | ||
// task represents the task that the worker will execute | ||
task chan Task | ||
// lastUsedTime represents the last time the worker was used | ||
lastUsedTime time.Time | ||
} | ||
|
||
type WorkerStack interface { | ||
Push(w *Worker) | ||
Pop() *Worker | ||
Len() int | ||
} | ||
|
||
type workerStack struct { | ||
workers []*Worker | ||
} |