Write-VCSPrompt in background thread (sample implementation)
I just wanted to share this with the team; please feel free to close this issue. My work computer is kinda slow thanks to a corporate virus scanner. In particular, posh-git's Write-VCSStatus slows down my prompt, so I wanted to see if I could run it in a background thread. The result is messy, but it works!
It starts a worker thread in the background within which it loads posh-git. The prompt function sends a message to the worker thread asking it to run Write-VCSStatus. Powershell.OnIdle events are used to wait for the response and re-render the prompt via a call to PSReadline's API. Re-rendering doesn't affect text you've entered, so effectively you can keep working at the prompt and/or wait a second for git status to appear.
https://gist.github.com/cspotcode/f45c9d92412becbe9201c8de63e4ff98
System Details
- posh-git version/path: 1.0.0-beta2
- PowerShell version: Windows PowerShell 5.1.17134.112
- Git version: 2.18.0.windows.1
- Operating system name and version: Windows 10 v1803
Great idea - this could be useful for folks working in large repos like Windows.
This has been tried before (#51, #52, #104), but I'm not opposed to trying it again with newer APIs. Why don't you open a PR with your code enabled by something like $GitPromptSettings.AsyncPrompt = $true so folks can test it out more easily?
Out of curiosity, have you tried using https://github.com/cmarcusreid/git-status-cache-posh-client?