This PR introduces a new experimental feature that modifies the $PodeContext.Server.State type from a standard hashtable to a threadsafe ConcurrentDictionary. This change aims to improve thread safety and simplify the manipulation of the state variable by removing the need to encapsulate operations within a scriptblock using Lock-PodeObject.
Changes
State Variable Update:
Changed the $PodeContext.Server.State type from a standard hashtable to a threadsafe [System.Collections.Concurrent.ConcurrentDictionary[string, PSObject]]::new([StringComparer]::OrdinalIgnoreCase).
Thread Safety Improvement:
By utilizing ConcurrentDictionary, thread safety is inherently managed, reducing the need for manual locking mechanisms.
Benefits
Improved Thread Safety:
ConcurrentDictionary provides built-in thread safety for all operations, eliminating race conditions and potential deadlocks associated with manual locking.
Simplified Code:
Operations involving the state variable no longer require encapsulation within scriptblocks using Lock-PodeObject, resulting in cleaner and more readable code.
Implementation Details
ConcurrentDictionary:
ConcurrentDictionary is used with StringComparer.OrdinalIgnoreCase to ensure case-insensitive keys.
The type definition is [System.Collections.Concurrent.ConcurrentDictionary[string, PSObject]]::new([StringComparer]::OrdinalIgnoreCase).
Enabling the Feature
There are two ways to enable this new experimental feature:
Summary
This PR introduces a new experimental feature that modifies the
$PodeContext.Server.State
type from a standard hashtable to a threadsafeConcurrentDictionary
. This change aims to improve thread safety and simplify the manipulation of the state variable by removing the need to encapsulate operations within a scriptblock usingLock-PodeObject
.Changes
$PodeContext.Server.State
type from a standard hashtable to a threadsafe[System.Collections.Concurrent.ConcurrentDictionary[string, PSObject]]::new([StringComparer]::OrdinalIgnoreCase)
.ConcurrentDictionary
, thread safety is inherently managed, reducing the need for manual locking mechanisms.Benefits
ConcurrentDictionary
provides built-in thread safety for all operations, eliminating race conditions and potential deadlocks associated with manual locking.Lock-PodeObject
, resulting in cleaner and more readable code.Implementation Details
ConcurrentDictionary
is used withStringComparer.OrdinalIgnoreCase
to ensure case-insensitive keys.[System.Collections.Concurrent.ConcurrentDictionary[string, PSObject]]::new([StringComparer]::OrdinalIgnoreCase)
.Enabling the Feature
There are two ways to enable this new experimental feature:
Inside the
server.psd1
file:Pass the
-Experimental
parameter toStart-PodeServer
: