我在PowerShell中探索函数式编程,而且我在执行嵌套函数时遇到问题:
function Get-ThreadsafeMessageAction {
param(
[System.Threading.Mutex] $mutex,
$action)
$mtx = $mutex
$act = $action
return { param([string] $message)
$mtx.WaitOne()
&$act $message
$mtx.ReleaseMutex()}
}
错误:
The expression after '&' in a pipeline element produced an object that was not valid.
It must result in a command name, a script block, or a CommandInfo object.
At C:\Users\username\Desktop\myscript.ps1:21 char:52
+ Invoke-Command -ScriptBlock {param($act) & $act $message } -A ...
+ ~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : BadExpression