Add task pool, minor changes
- Add task pool to smooth impact when list in config is pretty long - Update dependencies - Update config
This commit is contained in:
35
vendor/github.com/alitto/pond/worker.go
generated
vendored
Normal file
35
vendor/github.com/alitto/pond/worker.go
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
package pond
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// worker represents a worker goroutine
|
||||
func worker(context context.Context, waitGroup *sync.WaitGroup, firstTask func(), tasks <-chan func(), taskExecutor func(func(), bool)) {
|
||||
|
||||
// If provided, execute the first task immediately, before listening to the tasks channel
|
||||
if firstTask != nil {
|
||||
taskExecutor(firstTask, true)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
waitGroup.Done()
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-context.Done():
|
||||
// Pool context was cancelled, exit
|
||||
return
|
||||
case task, ok := <-tasks:
|
||||
if task == nil || !ok {
|
||||
// We have received a signal to exit
|
||||
return
|
||||
}
|
||||
|
||||
// We have received a task, execute it
|
||||
taskExecutor(task, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user