Skip to main content

⚠️ IMPORTANT This module is early in it´s development phase. Many API function and features are not yet available. You are welcome to contribute on GitHub to accelerate progress further.

PSQueue

This project has adopted the following policies CodeOfConduct Contributing Security

Project status

GitHub Workflow Status Codecov Platform PowerShell Gallery License docs changelog GitHub release (latest SemVer including pre-releases) GitHub release (latest SemVer including pre-releases)

About

PSQueue is a wrapper module for the .Net class System.Collections.Queue. This module mainly provides two benefits, the first is to make it easy to utilize the queue class in a powershell syntax way. The second reason is that queue objects created with this module adds additional functionality like metrics for items added and removed, counters for items added and removed per second and velocity. Every time an item is added or removed these performance metrics are calculated. This of course adds a small overhead and decreases performance and is very marginal. Unless the queue will process more than tens of thousands of addition and removals per sec it will not be noticeable.

Installation

To install from the PowerShell gallery using PowerShellGet run the following command:

Install-Module PSQueue -Scope CurrentUser

Usage

Start by initialize a new queue object

$Queue = Initialize-Queue

To add a new item to the queue use Add-QueueItem

Add-QueueItem -Queue $Queue -Item 'Foo'

To retreive the next item in queue use Get-NextQueueItem

$NextItemToProcess = Get-NextQueueItem -Queue $Queue

You can also "peek" at the next item in queue by using Show-NextQueueItem, the difference from Get-NextQueueItem is that the next item in queue is retreived but remains in the queue.

$NextItemInQueue = Show-NextQueueItem -Queue $Queue

You have two methods of emptying the queue, either by retreiving all items (Get-AllQueueItems) or by discarding all items (Clear-AllQueueItems)


# This will retreive all items and dequeue the items.
$AllRemainingQueueItems = Get-AllQueueItems -Queue $Queue

# This will also clear the queue but it does not return any items for the queue and is therefor faster
Clear-AllQueueItems -Queue $Queue

You can show performance metrics by using Measure-Queue

Measure-Queue -Queue $Queue