RamblingCookieMonster/Invoke-Parallel

How can we share variable state?

RamblingCookieMonster opened this issue · 3 comments

Had a question from another medium, boiled down to the lack of shared state (variables).

Will look into implementing something along the lines of Boe's synchronized hash table idea, or Dave Wyatt's Lock-Object.

Any idea if this will be implemented? I'm interested in being able to collect data from all runspaces in a single object, and then do something with that object when all runspaces complete.

Hi!

Unfortunately, the command is already going a bit overboard with parameters - rather than throw everything into invoke-parallel, I think it makes sense to keep this one separate - that said, if you have any ideas on implementing it in a straightforward way, would love to hear!

You can still do this though. By design, you can simply do:

$whatever = 1..100 | invoke-parallel {
    # Some silly example
    [pscustomobject]@{
        ComputerName = "Server$_"
        Blah = 1
    }
}

If you run into issues with certain items freezing, would could skip items that time out -NoCloseOnTimeout -RunSpaceTimeout 45 would ignore any item that takes longer than 45 seconds to run. Keep in mind memory from those frozen runspaces is chewed up until your powershell instance closes - usually not a problem, but worth knowing about.

On top of this, the two links from the issue still work pretty well if you want to play around with them.

Cheers!

Closing this out for now. If folks have more ideas on this that wouldn't clutter the parameters too much, I'd be open to it.

Cheers!