Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
santisq committed Oct 30, 2022
1 parent 9c5a5fc commit 06532b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
5 changes: 2 additions & 3 deletions PSParallelPipeline.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function Invoke-Parallel {
Get-Process | Invoke-Parallel {
$sync = $using:sync
$sync[$_.Name] += @( $_ )
} -ThrottleLimit 5
}
$sync
Expand All @@ -79,9 +79,8 @@ function Invoke-Parallel {
$sync = [hashtable]::Synchronized(@{})
Get-Process | Invoke-Parallel {
$sync = $using:sync
$sync[$_.Name] += @( $_ )
} -ThrottleLimit 5
} -ArgumentList @{ sync = $sync }
$sync
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ $message = 'Hello world from {0}'
```powershell
$sync = [hashtable]::Synchronized(@{})
0..10 | Invoke-Parallel {
Get-Process | Invoke-Parallel {
$sync = $using:sync
$sync.Add($_, 'hello')
} -ThrottleLimit 5
$sync[$_.Name] += @( $_ )
}
$sync
```

### EXAMPLE 4: Same as previous, but using `-ArgumentList` to pass the reference instance to the Runspaces
### EXAMPLE 4: Same as previous example but using `-ArgumentList` to pass the reference instance to the Runspaces

This method is the recommended when passing reference instances to the runspaces, `$using:` may fail in some situations.

```powershell
$sync = [hashtable]::Synchronized(@{})
0..10 | Invoke-Parallel {
$sync.Add($_, 'hello')
Get-Process | Invoke-Parallel {
$sync[$_.Name] += @( $_ )
} -ArgumentList @{ sync = $sync }
$sync
Expand Down
2 changes: 1 addition & 1 deletion tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $sync = [hashtable]::Synchronized(@{})
Get-Process | Invoke-Parallel {
$sync = $using:sync
$sync[$_.Name] += @( $_ )
} -ThrottleLimit 5
}

$sync

Expand Down

0 comments on commit 06532b0

Please sign in to comment.