-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from saantiaguilera/feature/sa/v2
V2
- Loading branch information
Showing
129 changed files
with
2,392 additions
and
6,168 deletions.
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
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,4 +1,5 @@ | ||
.idea/ | ||
.DS_Store | ||
|
||
*.prof | ||
*.test |
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
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,66 @@ | ||
package pipeline | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
) | ||
|
||
type ( | ||
ConcurrentStep[I, O any] struct { | ||
steps []Step[I, O] | ||
reduce reducer[O] | ||
} | ||
|
||
reducer[O any] func(context.Context, O, O) (O, error) | ||
) | ||
|
||
// NewConcurrentStep creates a step that will run each of the inner steps concurrently. | ||
// The step will wait for all of the steps to finish before returning. | ||
// | ||
// If one of them fails, the step will wait until everyone finishes and after that return the first encountered error. | ||
func NewConcurrentStep[I, O any](steps []Step[I, O], reduce reducer[O]) ConcurrentStep[I, O] { | ||
return ConcurrentStep[I, O]{ | ||
steps: steps, | ||
reduce: reduce, | ||
} | ||
} | ||
|
||
func (c ConcurrentStep[I, O]) Draw(graph Graph) { | ||
if len(c.steps) > 0 { | ||
var forkSteps []GraphDrawer | ||
for _, s := range c.steps { | ||
forkSteps = append(forkSteps, c.newStepGraphActivity(s)) | ||
} | ||
|
||
graph.AddConcurrency(forkSteps...) | ||
} | ||
} | ||
|
||
func (c ConcurrentStep[I, O]) Run(ctx context.Context, in I) (O, error) { | ||
if len(c.steps) == 0 { | ||
return *new(O), errors.New("cannot run with empty concurrent steps") | ||
} | ||
|
||
mres, err := spawnAsync(c.steps, func(s Step[I, O]) (O, error) { | ||
return s.Run(ctx, in) | ||
}) | ||
|
||
if err != nil { | ||
return *new(O), err | ||
} | ||
|
||
acc := mres[0] | ||
for _, v := range mres[1:] { | ||
acc, err = c.reduce(ctx, acc, v) | ||
if err != nil { | ||
return *new(O), err | ||
} | ||
} | ||
return acc, nil | ||
} | ||
|
||
func (c ConcurrentStep[I, O]) newStepGraphActivity(drawable DrawableGraph) GraphDrawer { | ||
return func(graph Graph) { | ||
drawable.Draw(graph) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.