Modern Swift concurrency#2
Merged
Merged
Conversation
…rrency Enable the Approachable Concurrency upcoming features for the executable target (NonisolatedNonsendingByDefault, InferIsolatedConformances) and modernize the remaining legacy-concurrency sites so the package is free of MainActor.run, GCD-as-concurrency, and dead imports. - Replace the MainActor.run write-lock around stream writes with an actor-isolated append(_:) on GameFinder, and hoist the JSONEncoder into a stored, init-once property so the concurrent task-group children serialize their output through the actor instead of bouncing to the main actor. - Drop the unused `import Dispatch` from GameFinder. - Rework the SIGINT handler from a DispatchSource(queue: .main) + escaping closure + Self.exit() into an AsyncStream of interrupts bridged into a structured withThrowingTaskGroup, and observe cancellation in findGames so a Ctrl-C cancels the search, lets in-flight games finish streaming, and appends the closing `]` before exiting cleanly. The DispatchSource signal source and signal(SIGINT, SIG_IGN) remain as the underlying primitive since there is no native async signal API; only their delivery is bridged to structured concurrency. The command-line interface, JSON output format, and exit code are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
5e61f72 to
bc73dd2
Compare
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.
Summary
Adopts the Approachable Concurrency upcoming features for the
GameGeneratorexecutable and modernizes the remaining legacy-concurrency sites so the package
is free of
MainActor.run, GCD-as-concurrency, and dead imports.NonisolatedNonsendingByDefaultandInferIsolatedConformanceson theexecutable target.
MainActor.runwrite-lock around stream writes with anactor-isolated
append(_:)onGameFinder, and hoists theJSONEncoderinto astored, init-once property so the concurrent task-group children serialize their
output through the actor instead of bouncing to the main actor.
import DispatchfromGameFinder.DispatchSource(queue: .main)+escaping closure +
Self.exit()into anAsyncStreamof interrupts bridgedinto a structured
withThrowingTaskGroup, with cancellation observed infindGames. A Ctrl-C now cancels the search through structured cancellation,lets in-flight games finish streaming, and appends the closing
]beforeexiting cleanly. The
DispatchSourcesignal source andsignal(SIGINT, SIG_IGN)remain as the underlying primitive (there is no native async signal API); only
their delivery is bridged to structured concurrency.
The command-line interface, JSON output format, and exit code are unchanged.
Verification
swift build --build-testssucceeds.smoke-tested manually: clean exit code 0, well-formed bracketed JSON, and
in-flight games flushed before exit.
🤖 Generated with Claude Code