8000 Add a generic file watcher function in HelpersCommon.psm1 by daxian-dbw · Pull Request #4775 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 5 commits into from
Sep 12, 2017

Conversation

daxian-dbw
Copy link
Member

Fix #4524

Add a generic file watcher function in HelpersCommon.psm1 and update some tests to use the Wait-FileToBePresent.

@@ -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
Copy link
Collaborator

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?

Copy link
Member Author
@daxian-dbw daxian-dbw Sep 11, 2017

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)) {
Copy link
Collaborator

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.

Copy link
Member Author

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
Copy link
Collaborator

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.

Copy link
Member Author
@daxian-dbw daxian-dbw Sep 11, 2017

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.

@daxian-dbw
Copy link
Member Author

The failure in AppVeyor is a known issue. It's fixed by #4806

@daxian-dbw daxian-dbw merged commit c06ffc4 into PowerShell:master Sep 12, 2017
@daxian-dbw daxian-dbw deleted the filewatcher branch September 12, 2017 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
31B2
0