From 789962fcbd17288588fd3c6c8ff985f97029562b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 5 Jun 2026 16:56:54 +0200 Subject: [PATCH 1/2] refactor: Replace Start-Job with Start-ThreadJob in Invoke-MyCommandAsync and Start-MyJob functions --- public/Invoke-MyCommandAsync.ps1 | 4 ++-- public/Start-MyJob.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/Invoke-MyCommandAsync.ps1 b/public/Invoke-MyCommandAsync.ps1 index 587484c..85aefac 100644 --- a/public/Invoke-MyCommandAsync.ps1 +++ b/public/Invoke-MyCommandAsync.ps1 @@ -34,10 +34,10 @@ function Invoke-MyCommandAsync { $scriptBlock = New-ScriptBlock -Command $cmd if ($PSCmdlet.ShouldProcess("Target", "Operation")) { - $job = Start-Job -ScriptBlock $scriptBlock + $job = Start-ThreadJob -ScriptBlock $scriptBlock } else { Write-Information $scriptBlock - $job = Start-Job -ScriptBlock {$null} + $job = Start-ThreadJob -ScriptBlock {$null} } $jobs += $job diff --git a/public/Start-MyJob.ps1 b/public/Start-MyJob.ps1 index 454bc6e..273d0bb 100644 --- a/public/Start-MyJob.ps1 +++ b/public/Start-MyJob.ps1 @@ -22,10 +22,10 @@ function Start-MyJob{ $scriptBlock = New-ScriptBlock -Command $cmd if ($PSCmdlet.ShouldProcess("Target", "Operation")) { - $job = Start-Job -ScriptBlock $scriptBlock + $job = Start-ThreadJob -ScriptBlock $scriptBlock } else { Write-Information $scriptBlock - $job = Start-Job -ScriptBlock {$null} + $job = Start-ThreadJob -ScriptBlock {$null} } return $job From 8279fa3c7d4e30131ea388e2bb93e4bf92c4e43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 5 Jun 2026 17:05:21 +0200 Subject: [PATCH 2/2] fid: Update test cases in InvokeHelperTest_JobInternal_Start_WhatIf to use return values --- InvokeHelperTest/public/Start-MyJob.test.ps1 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/InvokeHelperTest/public/Start-MyJob.test.ps1 b/InvokeHelperTest/public/Start-MyJob.test.ps1 index 569c011..392ebd7 100644 --- a/InvokeHelperTest/public/Start-MyJob.test.ps1 +++ b/InvokeHelperTest/public/Start-MyJob.test.ps1 @@ -15,19 +15,17 @@ function InvokeHelperTest_JobInternal_Start{ function InvokeHelperTest_JobInternal_Start_WhatIf{ $jobs = @() - $jobs += Start-MyJob -Command "command to be called1" -WhatIf @InfoParameters - Assert-Contains -Expected "command to be called1" -Presented $infoVar + $jobs += Start-MyJob -Command "return 1" -WhatIf @InfoParameters + Assert-Contains -Expected "return 1" -Presented $infoVar - $jobs += Start-MyJob -Command "command to be called2" -WhatIf @InfoParameters - Assert-Contains -Expected "command to be called2" -Presented $infoVar + $jobs += Start-MyJob -Command "return 2" -WhatIf @InfoParameters + Assert-Contains -Expected "return 2" -Presented $infoVar $waited = Wait-Job -Job $jobs $result = Receive-Job -Job $waited - Assert-Count -Expected 2 -Presented $result - Assert-IsNull -Object $result[0] - Assert-IsNull -Object $result[1] + Assert-isnull -Object $result } function InvokeHelperTest_JobInternal_Start_MultiCall{