Skip to content

Commit

Permalink
Remove runSync since it speeds-up ~30%
Browse files Browse the repository at this point in the history
  • Loading branch information
saantiaguilera committed Feb 10, 2020
1 parent 54d7b3b commit a04aadc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions pipeline_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@ func BenchmarkPipeline_Run(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StartTimer()
err := pipe.Run(graph, ctx)

b.StopTimer()

if err != nil {
b.Fail()
}
b.StartTimer()
}
}
12 changes: 0 additions & 12 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,3 @@ func spawnAsync(workers int, run func(index int) error) error {
wg.Wait()
return errResult.Get()
}

// Run synchronously a number of workers. If one of them fails, the operation is aborted and the error returned.
func runSync(workers int, run func(index int) error) error {
for i := 0; i < workers; i++ {
err := run(i)

if err != nil {
return err
}
}
return nil
}
11 changes: 8 additions & 3 deletions sequential_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package pipeline
type sequentialGroup []Stage

func (s sequentialGroup) Run(executor Executor, ctx Context) error {
return runSync(len(s), func(index int) error {
return s[index].Run(executor, ctx)
})
for _, stage := range s {
err := stage.Run(executor, ctx)

if err != nil {
return err
}
}
return nil
}

func (s sequentialGroup) Draw(graph GraphDiagram) {
Expand Down
11 changes: 8 additions & 3 deletions sequential_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package pipeline
type sequentialStage []Step

func (s sequentialStage) Run(executor Executor, ctx Context) error {
return runSync(len(s), func(index int) error {
return executor.Run(s[index], ctx)
})
for _, step := range s {
err := executor.Run(step, ctx)

if err != nil {
return err
}
}
return nil
}

func (s sequentialStage) Draw(graph GraphDiagram) {
Expand Down

0 comments on commit a04aadc

Please sign in to comment.