11---
22description : Introduces advanced functions that are a way to create cmdlets using scripts.
33Locale : en-US
4- ms.date : 01/02 /2025
4+ ms.date : 03/25 /2025
55online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced?view=powershell-7.6&WT.mc_id=ps-gethelp
66schema : 2.0.0
77title : about_Functions_Advanced
@@ -71,21 +71,19 @@ Advanced functions differ from compiled cmdlets in the following ways:
7171
7272## PipelineStopToken
7373
74- Beginning with PowerShell 7.6, you can access the ` PipelineStopToken ` property
75- on the ` $PSCmdlet ` variable to access a [ CancellationToken] [ 07 ] tied to the
76- PowerShell stop event source. This token will be automatically triggered when
77- the PowerShell pipeline has been requested to stop. It is designed to be used
78- with .NET methods that accept a ` CancellationToken ` overload so that the
79- method can exit when requested rather than wait until the method returns from
80- what it is doing.
74+ Beginning with PowerShell 7.6, ` $PSCmdlet ` includes the ` PipelineStopToken `
75+ property allowing access a [ CancellationToken] [ 07 ] tied to the PowerShell stop
76+ event source. The token is triggered when the PowerShell pipeline receives a
77+ request to stop. Use it with a .NET method that accepts a ` CancellationToken `
78+ overload to exit the method when requested rather than waiting until the method
79+ returns.
8180
82- A common example is if the function is calling a .NET async compatible API. In
83- the below example the function is calling ` HttpClient.GetStringAsync ` which
84- could take a while to respond if the network is slow or there is a lot of data
85- being returned.
81+ In the following example the function is calling ` HttpClient.GetStringAsync `
82+ that can take a while to respond when the network is slow or there is a lot of
83+ data being returned.
8684
8785``` powershell
88- Function Invoke-WebGetRequest {
86+ function Invoke-CancelableWebRequest {
8987 [CmdletBinding()]
9088 param(
9189 [Parameter(Mandatory=$true)]
@@ -99,7 +97,7 @@ Function Invoke-WebGetRequest {
9997 $PSCmdlet.PipelineStopToken).GetAwaiter().GetResult()
10098}
10199
102- Invoke-WebGetRequest -Url https://httpbin.org/delay/10
100+ Invoke-CancelableWebRequest -Url https://httpbin.org/delay/10
103101# Press ctrl+c to cancel
104102```
105103
0 commit comments