Repository navigation
Let a cancelled RDLImageLoader call stop waiting at once when others share its download - #434
Merged
Merged
Conversation
…share its download Each call has its own continuation, resumed by the actor with the result when the download ends or with a CancellationError when its caller is cancelled. The download is cancelled only when no call is left. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #434 +/- ##
==========================================
+ Coverage 94.75% 94.80% +0.04%
==========================================
Files 465 465
Lines 19457 19477 +20
==========================================
+ Hits 18437 18465 +28
+ Misses 1020 1012 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
A call to
RDLImageLoaderthat is cancelled stops waiting at once, with aCancellationError, even when other calls share its download. (Audit E18, first item.)RDLImageLoadercoalesces concurrent loads of the sameid: the first call starts the download, the others join it, and the download is cancelled when the last call that waits for it is cancelled. That part is unchanged. What was not prompt was the call that left while others stayed: it awaited the sharedTask, and awaiting aTaskis not interrupted by the cancellation of the caller, so it returned only once the image had arrived (the sole call of a download was prompt, since it was the last and cancelled the download itself). A row scrolled off screen while the same image was still wanted elsewhere kept waiting.The change
InFlight.waitersby the actor. The download's task no longer returns the image to its waiters: when it ends it callscomplete(id:generation:with:), which removes the download and resumes every continuation still waiting with the result.leave(id:generation:waiter:): its continuation is resumed withCancellationError, and the download is cancelled only if it was the last one.generationstill keeps a late cancellation of a call of an earlier download from touching a newer one.complete, byleave, never by both: whichever runs first removes it).CancellationErrorunless the result was already delivered.Tests (
RDLImageLoaderTests, 14 in all)cancellingOneOfTwoWaiters_returnsTheCancelledOneAtOnce_whileTheRequestStillRuns: the cancelled call throwsCancellationErrorwhile the shared request is still held (a gate the test opens later), the other call then gets its image, and the request was started once and never cancelled.cancellingEveryWaiterOfASharedRequest_cancelsIt: the request is cancelled only after the second and last call leaves, and both calls throw.aCallerThatJoinsAfterAnotherLeft_getsTheSameRequest: a call that arrives after another left, while the request runs, joins it.waiterCountForTesting(id:)is how the tests wait for a call to have joined or left, in place of a sleep.macOS full suite and the URLSession-only build pass locally.
swift format lint --strictis clean.🤖 Generated with Claude Code