Repository navigation
Keep continue and break in a callback inside the callback - #39
Merged
Merged
Conversation
PowerShell sends continue and break to the nearest loop on the call stack, across the module boundary, so one in a callback landed in one of the kit's own loops. A continue in -OnComplete skipped that job's dispose, slot release and group count and the dispatcher looped forever; a break dropped running jobs from tracking or the rest of a worker's results. The same went for every other callback and for the message handler. Every call to a user callback now goes through Invoke-PkCallback, which runs it inside a do/while of its own, so either keyword only ends the callback, as return would, and the kit warns once per callback per call, naming it. The message handler gets the same wrap, with its warning on the console. The README says to use return, and what a labeled break to the caller's own loop does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Invoke-PkCallback now hands back exactly what the callback returned, so a collection returned whole stays one value. A message handler that uses continue or break counts as having returned, with one console warning per handler instead of one per message. Adds harness checks for both and for a labeled break out of a callback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
PowerShell sends
continueandbreakto the nearest loop on the call stack, even across a module boundary. In a callback, that loop is one of the kit's own. For example, acontinuein-OnCompleteskipped that job's dispose, slot release and group count, so the dispatcher looped forever after every program had finished. Abreakdropped running jobs from tracking, or the rest of a worker's results in-ResultHandler. The same applied to every other callback and to the message handler. It's easy to hit, becausecontinueis the usual way to skip an item in a loop.What changed
Invoke-PkCallback. It runs the callback inside ado { } while ($false)of its own, so either keyword only ends the callback, asreturnwould. The kit carries on and warns once per callback per call, naming the callback. It hands back exactly what the callback returned, so a collection returned whole (return ,$list) stays one value. This covers all the dispatcher, batch and runspace-engine callbacks:-OnComplete,-JobFinalize,-JobStarter,-JobPollCompleted,-JobAbortCleanup,-GroupCompleteCallback,-GroupReleaseCheck,-AbortPollCallback,-GroupProvider,-JobBuilder,-ResultHandler,-PollCallback,-NextJobProviderand-JobCrashedHandler.Invoke-PkMessageHandler. Its warning goes to the console, once per handler, since a warning is itself a message.breakaimed at the caller's own loop still leaves the call. The call stops there and kills its programs.return, and what the kit does with each keyword.How it was tested
New harness section AH runs each keyword in each callback in its own
[PowerShell]with a 20 s limit, so a hang fails instead of stalling the suite. Each case checks that the run finishes with the right results and exactly one warning. All 30 cases failed before the change: most hung, and the rest lost results or gave no warning. There are also checks that a group returned whole as a one-element array stays an array, and that a labeled break out of-OnCompleteleaves the call with no programs left running. The harness passes on Windows PowerShell 5.1 and PowerShell 7 (431 assertions each).🤖 Generated with Claude Code