Do parallel commands execute in the pipeline?

I noticed an interesting statement in the PowerShell Notes for Professionals white paper, “In a series of pipelines, each function works in parallel with another, like parallel threads” :

enter image description here

It is right? if yes, is there any technical documentation that supports this statement?

+5
source share
1 answer

It is true, but not at all.

What do I mean with that? First, let's remove your documentation question. The following paragraph is §3.13 of the PowerShell version 3.0 language specification :

, , . , -, . . , , , .

, .

, .


, , . , .

PowerShell - , :

, BeginProcessing() . "" - - , .

, , .


!

begin, process end, , .

5 , , Write-Host, , (. ):

PS C:\> 1..5 |first |second |third |Out-Null

pipeline processing

, PowerShell -OutBuffer, :

pipeline buffering

, !


, .

Write-Host , , , , .

function Test-Pipeline {
  param(
    [Parameter(ValueFromPipeline)]
    [psobject[]]$InputObject
  )

  begin {
    $WHSplat = @{
      ForegroundColor = switch($MyInvocation.InvocationName){
        'first' {
          'Green'
        }
        'second' {
          'Yellow'
        }
        'third' {
          'Red'
        }
      }
    }
    Write-Host "Begin $($MyInvocation.InvocationName)" @WHSplat
    $ObjectCount = 0
  }

  process {
    foreach($Object in $InputObject) {
      $ObjectCount += 1
      Write-Host "Processing object #$($ObjectCount) in $($MyInvocation.InvocationName)" @WHSplat
      Write-Output $Object
    }
  }

  end {
    Write-Host "End $($MyInvocation.InvocationName)" @WHSplat
  }

}

Set-Alias -Name first  -Value Test-Pipeline
Set-Alias -Name second -Value Test-Pipeline
Set-Alias -Name third  -Value Test-Pipeline
+9

Source: https://habr.com/ru/post/1692919/


All Articles