Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add a generic file watcher function in HelpersCommon.psm1#4775

Merged
daxian-dbw merged 5 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
daxian-dbw:filewatcherdaxian-dbw/PowerShell:filewatcherCopy head branch name to clipboard
Sep 12, 2017
Merged

Add a generic file watcher function in HelpersCommon.psm1#4775
daxian-dbw merged 5 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
daxian-dbw:filewatcherdaxian-dbw/PowerShell:filewatcherCopy head branch name to clipboard

Conversation

@daxian-dbw

Copy link
Copy Markdown
Member

Fix #4524

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


# Loop until the script block evaluates to true
while (-not ($sb.Invoke())) {
# If the timeout period has passed, return false

Copy link
Copy Markdown
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?

@daxian-dbw daxian-dbw Sep 11, 2017

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@daxian-dbw daxian-dbw Sep 11, 2017

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.