more things

This commit is contained in:
cubixle
2021-07-27 21:09:29 +01:00
parent 2ddeeea267
commit cb8d79fca3
7 changed files with 196 additions and 46 deletions
+45 -12
View File
@@ -1,21 +1,54 @@
package l1
import (
"fmt"
"sync"
)
// Start starts the runner.
func (r *Runner) Start() error {
jobChan := make(chan string, r.MaxParrellConnections)
// resultsChan := make(chan struct{})
type Task struct {
Target string
Result *Result
F F
}
for i := 0; i < r.MaxParrellConnections; i++ {
go func(jobChan chan string) {
for t := range jobChan {
r.RunFunc(t)
}
}(jobChan)
type pool struct {
tasks []*Task
concurrency int
tasksChan chan *Task
wg sync.WaitGroup
}
func newPool(tasks []*Task, concurrency int) *pool {
return &pool{
tasks: tasks,
concurrency: concurrency,
tasksChan: make(chan *Task),
}
}
// run will run all work within the pool.
func (p *pool) run() {
for i := 0; i < p.concurrency; i++ {
go p.work()
}
return fmt.Errorf("unimplemented")
p.wg.Add(len(p.tasks))
for _, t := range p.tasks {
p.tasksChan <- t
}
close(p.tasksChan)
p.wg.Wait()
}
func (p *pool) work() {
for t := range p.tasksChan {
if t.F == nil {
continue
}
res := t.F(t.Target)
t.Result = res
p.wg.Done()
}
}