File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ function Get-WebSocket {
8484 {$args.commit.record.text -match '[\p{IsHighSurrogates}\p{IsLowSurrogates}]+'}={
8585 $matches.0
8686 }
87- }
87+ }
8888 #>
8989 [CmdletBinding (PositionalBinding = $false )]
9090 [Alias (' WebSocket' )]
@@ -214,7 +214,7 @@ function Get-WebSocket {
214214
215215 if (-not $WebSocketUri.Scheme ) {
216216 $WebSocketUri = [uri ]" wss://$WebSocketUri "
217- }
217+ }
218218
219219 if (-not $BufferSize ) {
220220 $BufferSize = 16 kb
@@ -306,8 +306,22 @@ function Get-WebSocket {
306306 if (-not $name ) {
307307 $Name = $WebSocketUri
308308 }
309-
310- Start-ThreadJob - ScriptBlock $SocketJob - Name $Name - InitializationScript $InitializationScript - ArgumentList $Variable
309+
310+ $existingJob = foreach ($jobWithThisName in (Get-Job - Name $Name )) {
311+ if (
312+ $jobWithThisName.State -in ' Running' , ' NotStarted' -and
313+ $jobWithThisName.WebSocket -is [Net.WebSockets.ClientWebSocket ]
314+ ) {
315+ $jobWithThisName
316+ break
317+ }
318+ }
319+
320+ if ($existingJob ) {
321+ $existingJob
322+ } else {
323+ Start-ThreadJob - ScriptBlock $SocketJob - Name $Name - InitializationScript $InitializationScript - ArgumentList $Variable
324+ }
311325 } elseif ($WebSocket ) {
312326 if (-not $name ) {
313327 $name = " websocket"
You can’t perform that action at this time.
0 commit comments