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 {
84
84
{$args.commit.record.text -match '[\p{IsHighSurrogates}\p{IsLowSurrogates}]+'}={
85
85
$matches.0
86
86
}
87
- }
87
+ }
88
88
#>
89
89
[CmdletBinding (PositionalBinding = $false )]
90
90
[Alias (' WebSocket' )]
@@ -214,7 +214,7 @@ function Get-WebSocket {
214
214
215
215
if (-not $WebSocketUri.Scheme ) {
216
216
$WebSocketUri = [uri ]" wss://$WebSocketUri "
217
- }
217
+ }
218
218
219
219
if (-not $BufferSize ) {
220
220
$BufferSize = 16 kb
@@ -306,8 +306,22 @@ function Get-WebSocket {
306
306
if (-not $name ) {
307
307
$Name = $WebSocketUri
308
308
}
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
+ }
311
325
} elseif ($WebSocket ) {
312
326
if (-not $name ) {
313
327
$name = " websocket"
You can’t perform that action at this time.
0 commit comments