-
Notifications
You must be signed in to change notification settings - Fork 115
PSReadLine holds on to thread that Polaris uses #136
Comments
Yep, same thing. A couple things you could do:
|
Yeah Polaris running as a job works so 3 is at least fine for now.... |
Got some feedback on this today from a few people. Really should address this somehow... I don't know if I want to go down the "private" contract plan (although I appreciate @lzybkr for adding that). I wonder if I should stop relying on Sucks to have to take away the prompt from the user, but this is what Node.js does today so I'm not too upset. |
We could offer two modes maybe? |
I opened PowerShell/PowerShell#8478 to see if the PowerShell team has any suggestions or believes it to be a bug. |
Reopened in PowerShell/PSReadLine#835 as it is a PSReadline issue not a PowerShell issue. |
Thanks @Tiberriver256 😃 I think 2 modes makes sense.
|
Question from #194 via @mikeTWC1984:
Moved to keep discussion in one main thread |
There have been a few suggestions above and my guess as to why it works in VSCode is because of what SeeminglyScience has done to make it work (as referenced above). @SeeminglyScience - Do you have the code handy somewhere you used to override the delegate in PSES? |
@Tiberriver256 Now that I think about it, the same route PSES takes isn't feasible here. PSRL only checks for the override at process start (or more specifically, it only checks the first time it calls Even if you did choose to do that, you'd still need to rip out the custom async version of Tbh I'd recommend putting some more attention on dotnet/corefx#25036 over reusing our hacky workarounds. |
OK, thanks for the info. It doesn't sound like that ReadKey issues is anywhere close to resolution though. I was looking for a hack just because I want to use Polaris as a back-end for Jupiter like app, so need to keep PSReadline. One of the suggestion above was about running it as job, but didn't work. But it works if running in a separate runspace, so I'll stick to it for now. Other was to use while loop vs event, just not sure how to implement it. |
I'll leave my workaround below, in case anybody also looking for options function New-PolarisServer { param($port=8888)
$ps = [powershell]::create()
$info = $ps.AddScript({param($p)
Remove-Module PSReadline
New-PolarisGetRoute -Path "/" -Scriptblock {
$response.send(($PSVersionTable | Select-Object OS, PSEdition, Platform, PSVersion | ConvertTo-Json))
}
Start-Polaris -port $p
}).AddParameter("p", $port).Invoke()
$AddRoute = { param([string]$route, [scriptblock]$sb, [string]$method="GET")
$this.ps.Commands.Clear()
$this.ps.AddCommand("New-PolarisRoute").AddParameters(@{
Path=$route; ScriptBlock=$sb; Method=$method; Force=$true
}).Invoke()
}
$Dispose = {
$this.ps.Commands.Clear()
$this.ps.AddCommand("Stop-Polaris").AddCommand("Clear-Polaris").Invoke()
$this.ps.Dispose()
}
$obj = [PSCustomObject]@{ ps = $ps; info = $info }
$obj | Add-Member -MemberType ScriptMethod -Name AddRoute -Value $AddRoute
$obj | Add-Member -MemberType ScriptMethod -Name Dispose -Value $Dispose
return $obj
}
<# Usage
$p = New-PolarisServer -port 8000
$p.AddRoute("/hello", {$response.send("Hello there")} )
iwr http://localhost:8000/hello
$p.Dispose()
#> |
On macOS, Polaris, (which uses Register-ObjectEvent) hangs until you hit a key in the terminal. Then it processes the request.
This looks suspiciously similar to the issue we saw in PowerShell Editor Services that @SeeminglyScience fixed.
I haven't tested on Windows, but I have a feeling this doesn't happen.
The text was updated successfully, but these errors were encountered: