Created
April 13, 2022 07:37
-
-
Save affieuk/a5ce0480c7ab9d739956b046d7722735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original form stackoverflow, can find the uri, answer by mklement0 | |
$start = Get-Date | |
$queue = [System.Collections.Concurrent.ConcurrentQueue[string]]::new() | |
$job = Start-ThreadJob { | |
$queue = $using:queue | |
$item = $null | |
while ($true) { | |
while ($queue.TryDequeue([ref] $item)) { | |
if ("`0" -eq $item) { 'Quitting...'; return } | |
"[$item]" | |
} | |
Start-Sleep -MilliSeconds 100 | |
} | |
} | |
1..10 | ForEach-Object { | |
$queue.Enqueue($_) | |
$job | Receive-Job | |
} | |
$queue.Enqueue("`0") | |
$job | Receive-Job -Wait -AutoRemoveJob | |
New-TimeSpan -Start $start -End (Get-Date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment