Skip to content

v1.1.6

Compare
Choose a tag to compare
@santisq santisq released this 18 Jun 04:24
· 68 commits to main since this release
82e804f

What's Changed

v1.1.6 Details

Re-implements Invoke-Parallel in C#. This new version shares the same capabilities as the previous one and offers the following improvements:

Pipeline streaming capabilities

Invoke-Parallel v1.1.5

Measure-Command {
    1 | Invoke-Parallel { 0..10 | ForEach-Object { Start-Sleep 1; $_ } } | Select-Object -First 1
} | Select-Object TotalSeconds

# TotalSeconds
# ------------
#       11.10

Invoke-Parallel v1.1.6

Measure-Command {
    1 | Invoke-Parallel { 0..10 | ForEach-Object { Start-Sleep 1; $_ } } | Select-Object -First 1
} | Select-Object TotalSeconds

# TotalSeconds
# ------------
#        1.06

Support for CommonParameters

ForEach-Object v7.5.0.3

This is something missing on ForEach-Object -Parallel as of v7.5.0.3.

PS \> 0..5 | ForEach-Object -Parallel { Write-Error $_ } -ErrorAction Stop
# ForEach-Object: The following common parameters are not currently supported in the Parallel parameter set:
# ErrorAction, WarningAction, InformationAction, PipelineVariable

Invoke-Parallel v1.1.6

A few examples, they should all work properly, please submit an issue if not 😅.

PS \> 0..5 | Invoke-Parallel { Write-Error $_ } -ErrorAction Stop
# Invoke-Parallel: 0

PS \>  0..5 | Invoke-Parallel { Write-Warning $_ } -WarningAction Stop
# WARNING: 1
# Invoke-Parallel: The running command stopped because the preference variable "WarningPreference" or common parameter is set to Stop: 1

PS \> 0..5 | Invoke-Parallel { $_ } -PipelineVariable pipe | ForEach-Object { "[$pipe]" }
# [0]
# [1]
# [5]
# [2]
# [3]
# [4]

Input Script Block check

This check was missing in previous version.

PS \> { 1 + 1 } | Invoke-Parallel { & $_ }
# Invoke-Parallel: Piped input object cannot be a script block. Passed-in script block variables are not supported, and can result in undefined behavior.

Improved Script Block checks for variables passed in via $using: keyword

Invoke-Parallel v1.1.5

PS \> $var = @{ foo = @{ bar = { 1 + 1 } }}
PS \> 1 | Invoke-Parallel { & $using:var['foo']['bar'] }
# 2

Invoke-Parallel v1.1.6

PS \> $var = @{ foo = @{ bar = { 1 + 1 } }}
PS \> 1 | Invoke-Parallel { & $using:var['foo']['bar'] }
# Invoke-Parallel: A $using: variable cannot be a script block. Passed-in script block variables are not supported, and can result in undefined behavior.

Improved -TimeOutSeconds error message

Invoke-Parallel v1.1.5

PS \> 0..10 | Invoke-Parallel { $_; Start-Sleep 5 } -TimeoutSeconds 3
# Invoke-Parallel: The pipeline has been stopped.
# Invoke-Parallel: The pipeline has been stopped.
# Invoke-Parallel: The pipeline has been stopped.
# Invoke-Parallel: The pipeline has been stopped.
# Invoke-Parallel: The pipeline has been stopped.

Invoke-Parallel v1.1.6

PS \> 0..10 | Invoke-Parallel { $_; Start-Sleep 5 } -TimeoutSeconds 3
# 0
# 1
# 3
# 2
# 4
# Invoke-Parallel: Timeout has been reached.

Accept $null as input

Same as ForEach-Object -Parallel, now you can pipe $null to this cmdlet.

PS \> $null | Invoke-Parallel { 'hi' }
# hi

New parameter aliases

Parameter Alias
ThrottleLimit tl
TimeOutSeconds to
Variables vars
Functions funcs
UseNewRunspace unr

Full Changelog: v1.1.5...v1.1.6