diff options
| author | Will Hawkins <[email protected]> | 2023-12-13 19:56:03 -0500 |
|---|---|---|
| committer | Will Hawkins <[email protected]> | 2024-01-04 19:10:37 -0500 |
| commit | f3990f950277c2f61e0e1811b4b8a81fc0219da4 (patch) | |
| tree | 6969e4ac2c4e94e75fe2e0c5581da5c07785dce8 /executor/executor.go | |
| parent | 552f01ad73248474553ce471695745db58c862ea (diff) | |
[Feature] Support for testing upload/download in parallel
Use the `--rpm.parallel` to test in parallel mode. The default testing
mode is serial.
Signed-off-by: Will Hawkins <[email protected]>
Diffstat (limited to 'executor/executor.go')
| -rw-r--r-- | executor/executor.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/executor/executor.go b/executor/executor.go new file mode 100644 index 0000000..22c1235 --- /dev/null +++ b/executor/executor.go @@ -0,0 +1,53 @@ +package executor + +import ( + "sync" +) + +type ExecutionMethod int + +const ( + Parallel ExecutionMethod = iota + Serial +) + +type ExecutionUnit func() + +func (ep ExecutionMethod) ToString() string { + switch ep { + case Parallel: + return "Parallel" + case Serial: + return "Serial" + } + return "Unrecognized execution method" +} + +func Execute(executionMethod ExecutionMethod, executionUnits []ExecutionUnit) *sync.WaitGroup { + waiter := &sync.WaitGroup{} + + // Make sure that we Add to the wait group all the execution units + // before starting to run any -- there is a potential race condition + // otherwise. + (*waiter).Add(len(executionUnits)) + + for _, executionUnit := range executionUnits { + // Stupid capture in Go! Argh. + executionUnit := executionUnit + + invoker := func() { + executionUnit() + (*waiter).Done() + } + switch executionMethod { + case Parallel: + go invoker() + case Serial: + invoker() + default: + panic("Invalid execution method value given.") + } + } + + return waiter +} |
