-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add a generic file watcher function in HelpersCommon.psm1 #4775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and 8000 privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -11,14 +11,35 @@ function Wait-UntilTrue | |||
|
|||
# Loop until the script block evaluates to true | |||
while (-not ($sb.Invoke())) { | |||
# If the timeout period has passed, return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, make sense to enhance Invoke()
to support timeout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do async invocation via powershell API, though the experience is not optimal.
$startTime = [DateTime]::Now | ||
|
||
# Loop until the file is present | ||
while (-not (Test-Path $File)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use Wait-UntilTrue
? We duplicate code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I will change it.
while (((Get-Date) - $startTime).TotalSeconds -lt 10 -and (-not (Test-Path "$HOME/nativeCommandProcessor.Success"))) { | ||
Start-Sleep -Milliseconds 100 | ||
} | ||
Wait-FileToBePresent -File "$HOME/nativeCommandProcessor.Success" -TimeoutInSeconds 10 -IntervalInMilliseconds 100 > $null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every use we add ">$null" - so maybe do this internally in Wait-FileToBePresent ? If we need we could add -Passthrou
And why not use Out-Null? It is optimized for pipelines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change to ignore output in Wait-FileToBePresent
. -PassThru
can be added when there is a need coming up.
As for Out-Null, I think the optimization was to make Out-Null
same as > $null
when it's the last command in a pipeline, namely writing to null pipe directly without going through the cmdlet.
The failure in AppVeyor is a known issue. It's fixed by #4806 |
Fix #4524
Add a generic file watcher function in HelpersCommon.psm1 and update some tests to use the
Wait-FileToBePresent
.