proxb / PoshRSJob

Provides an alternative to PSjobs with greater performance and less overhead to run commands in the background, freeing up the console and allowing throttling on the jobs.
MIT License
541 stars 87 forks source link

Empty Pipe runs One job instead of Zero #197

Open fjf2002 opened 5 years ago

fjf2002 commented 5 years ago

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
MVKozlov commented 5 years ago

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

fjf2002 commented 5 years ago

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.

MVKozlov commented 5 years ago

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

fjf2002 commented 5 years ago

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.

MVKozlov commented 5 years ago

so, where the code example ? ;-)