Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ParallelKit.Harness.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ Test-Assert ($seen.Count -eq 6) "-OnComplete fires for each command that ran"
Test-Assert (-not $batch.Aborted) "a clean batch is not marked aborted"
$wd = Invoke-PkProcessBatch -Commands @(@{ FilePath = $cmdExe; Arguments = '/c cd'; WorkingDirectory = $env:SystemRoot }) -MaxConcurrent 1
Test-Assert ($wd.Results[0].Stdout.Trim() -ieq $env:SystemRoot) "a command's WorkingDirectory is honored"
# A foreach over nothing yields $null, not an empty array - the usual way to build the list when no files match.
$noCommands = foreach ($x in @()) { @{ FilePath = $cmdExe; Arguments = '/c exit 0' } }
$emptyBatch = $null
try { $emptyBatch = Invoke-PkProcessBatch -Commands $noCommands -MaxConcurrent 2 } catch { Write-Host " empty batch threw: $_" }
Test-Assert ($null -ne $emptyBatch -and $emptyBatch.Results.Count -eq 0 -and -not $emptyBatch.Aborted) "a batch given `$null (an empty foreach) returns no results"
Write-Host ""

# ==============================================================================
Expand Down
8 changes: 7 additions & 1 deletion ParallelKit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1155,8 +1155,11 @@ function Invoke-PkProcessBatch {
# Returns @{ Results; Aborted; ForceKilledCount }; each result is
# @{ Command; ExitCode; Stdout; Stderr; StreamTimedOut; StreamError; StartError; Aborted },
# every field always present - keep the three places that build one in sync.
# $Commands may be $null: a foreach that matches nothing yields $null, not
# an empty array, and an empty batch should just return no results.
param(
[Parameter(Mandatory)]
[AllowNull()]
[AllowEmptyCollection()]
[hashtable[]]$Commands,
[int]$MaxConcurrent = 4,
Expand All @@ -1176,7 +1179,10 @@ function Invoke-PkProcessBatch {
$jobBuilder = {
param($group)
$jobs = [System.Collections.Generic.List[hashtable]]::new()
foreach ($c in $Commands) { $jobs.Add(@{ FilePath = $c['FilePath']; Arguments = [string]$c['Arguments']; WorkingDirectory = [string]$c['WorkingDirectory']; Command = $c }) }
foreach ($c in $Commands) {
if ($null -eq $c) { continue }
$jobs.Add(@{ FilePath = $c['FilePath']; Arguments = [string]$c['Arguments']; WorkingDirectory = [string]$c['WorkingDirectory']; Command = $c })
}
return $jobs
}.GetNewClosure()

Expand Down
Loading