mirror of
https://github.com/cubixle/l1.git
synced 2026-04-24 22:54:47 +01:00
more things
This commit is contained in:
25
l1.go
25
l1.go
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// F defines the function type for runners.
|
||||
type F func(target string) error
|
||||
type F func(target string) *Result
|
||||
|
||||
// Runner
|
||||
type Runner struct {
|
||||
@@ -15,6 +15,7 @@ type Runner struct {
|
||||
RunTime time.Duration
|
||||
RunFunc F
|
||||
Target string
|
||||
results []*Result
|
||||
}
|
||||
|
||||
func NewRunner(opts ...Opt) (*Runner, error) {
|
||||
@@ -39,3 +40,25 @@ func NewRunner(opts ...Opt) (*Runner, error) {
|
||||
func (r *Runner) SetOpt(o Opt) {
|
||||
o(r)
|
||||
}
|
||||
|
||||
func (r *Runner) Execute() {
|
||||
tasks := []*Task{}
|
||||
for i := 0; i < r.MaxConnections; i++ {
|
||||
tasks = append(tasks, &Task{Target: r.Target, F: r.RunFunc})
|
||||
}
|
||||
// create the pool and process the tasks.
|
||||
pool := newPool(tasks, r.MaxParrellConnections)
|
||||
// the tasks are updated in memory so we don't expect a return here.
|
||||
pool.run()
|
||||
for _, t := range tasks {
|
||||
r.results = append(r.results, t.Result)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Runner) Results() *results {
|
||||
res := &results{
|
||||
Results: r.results,
|
||||
Target: r.Target,
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user