New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clean
block to script block as a peer to begin
, process
, and end
to allow easy resource cleanup
#15177
Add clean
block to script block as a peer to begin
, process
, and end
to allow easy resource cleanup
#15177
Commits on Oct 11, 2021
-
-
♻️ Refactor & address code review
- Move cleanup invocation into discrete method for CompiledScriptBlock - Tidy code paths in CompiledScriptBlock and DlrScriptCommandProcessor - Finish renaming work from dispose->cleanup - Rename critical region->critical section - Refactor disposal in CommandProcessorBase to avoid unnecessary paths
-
-
-
♻️ Refactor dispose in CommandProcessorBase
- Rename helper method. - Ensure DlrScriptCommandProcessor can't invoke Cleanup more than once
-
🔧 Adjust scope and error handling
- 🐛 fix error duplication
-
♻️ Avoid double type check for cleanup
Moving half of the cleanup logic to DlrScriptCommandProcessor lets us avoid the double type check/cast and handle script functions exclusively in DlrScriptCommandProcessor. Remaining branch for PSScriptCmdlet is retained in the base class's `Dispose()` method itself (moved up the stack one method).
-
- Explicit type for variable declaration - Ensure we mark cleanup as completed if there is no cleanup block. - Check depth before taking the lock
-
♻️ Move duplicated scope handling to method
This method could also be utilised in all the Begin/Process/End paths. However, they each have a very slightly different version of the code, do things in different orders, and split up certain parts of the code. We can revisit whether we want to refactor those code paths to use the new method in future, but for now this avoids duplicating the code from here to DlrScriptCommandProcessor, which would introduce complications.
-
♻️ Refactor critical section logic
With some review changes, it appears we're able to use Monitor methods instead of a semaphore as was previously required. Also added some comments.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
1. not support directly invoking the 'clean' block of a script block. 2. not support a script block with the 'clean' block for '.ForEach' magic method. 3. make 'clean' block mimic the 'finally' clause 4. add a few more tests
-
-
-
-
-
-