PoshRSJob icon indicating copy to clipboard operation
PoshRSJob copied to clipboard

Empty Pipe runs One job instead of Zero

Open fjf2002 opened this issue 6 years ago • 5 comments

Do you want to request a feature or report a bug? In my opinion this is a bug, cf.

@() | foreach { 1 }

What is the current behavior? Start-RSJob runs one job.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

@() | Start-RSJob { 1 } | wait-rsjob | Receive-RSJob

... outputs "1" ...

What is the expected behavior? ... instead of nothing.

Which versions of Powershell and which OS are affected by this issue? Did this work in previous versions of our scripts? Powershell 5.1, Windows Server 2016

Please provide a code example showing the issue, if applicable:

@() | Start-RSJob { 1 } | wait-rsjob | Receive-RSJob

fjf2002 avatar Dec 31 '18 14:12 fjf2002

I think this is not a bug, because Foreach-Object can't work without pipeline at all but Start-RSJob can

MVKozlov avatar Dec 31 '18 14:12 MVKozlov

Well, I insist that Start-RSJob "does the wrong thing" on an empty pipeline. Each time I use Start-RSJob on a pipeline, I need boilerplate code to catch this edge case.

fjf2002 avatar Jan 07 '19 17:01 fjf2002

so, may be you have a method to determine if there is empty pipeline or no pipeline? If so that can be implemented

MVKozlov avatar Jan 07 '19 19:01 MVKozlov

Yep, and you could call the method foreach-rsparallel or something like that.

Nevertheless Start-RSJob on its own would still "do the wrong thing" on an empty pipeline. I consider that a bug.

The problem is, Start-RSJob currently tries to solve two partially contradicting tasks, i.e.

  1. Starting one job with no input and
  2. Starting a number of jobs that work on the pipeline.

fjf2002 avatar Jan 07 '19 19:01 fjf2002

so, where the code example ? ;-)

MVKozlov avatar Jan 08 '19 11:01 MVKozlov