Skip to content

Instantly share code, notes, and snippets.

@affieuk
Created April 13, 2022 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save affieuk/a5ce0480c7ab9d739956b046d7722735 to your computer and use it in GitHub Desktop.
Save affieuk/a5ce0480c7ab9d739956b046d7722735 to your computer and use it in GitHub Desktop.
# 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