Network request cancellation (rebased onto the upstream sync) - #4
Merged
Merged
Conversation
- Introduced `CancellationToken` class to manage request cancellations. - Updated `CacheManager`, `BaseCacheManager`, and `FileService` interfaces to accept `CancellationToken`. - Enhanced file fetching methods to throw `CancelledException` when requests are cancelled. - Added tests for cancellation functionality in `HttpFileService` and `CancellationToken` behavior.
- Updated `ImageCacheManager` methods to accept `CancellationToken` for file fetching operations. - Ensured cancellation support is integrated into both direct file retrieval and resized image handling.
- Changed the constructor to ensure a default http.Client is used if none is provided. - Updated request handling to utilize AbortableRequest for better cancellation support. - Modified tests to reflect the new behavior, ensuring that cancellation after response completion does not throw an exception.
- Added checks to prevent operations on already cancelled requests in `CancellationToken`. - Enhanced `WebHelper` to handle cancellation before starting downloads and during queue processing. - Ensured proper cleanup of subjects associated with cancelled requests to prevent memory leaks.
- Added multiple cancellation checks throughout the file update process in `WebHelper`. - Ensured that cancellation is checked before and after asynchronous operations, including downloads and file saves. - Updated `_manageResponse` and `_saveFile` methods to accept `CancellationToken` for improved cancellation support.
Rebuilds test/mock.mocks.dart against mockito 5.8.1 and applies dart format to the cancellation changes so CI's format check passes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCmKSRuHNETmfGu2TffVzo
flutter_cache_manager_firebase depends on flutter_cache_manager ^3.4.2 from pub.dev, which has no CancellationToken. FirebaseHttpFileService overrides HttpFileService.get, so once that signature gained a cancellationToken parameter the package stopped analyzing: error - Undefined class 'CancellationToken' error - The named parameter 'cancellationToken' isn't defined Override the dependency with the sibling package in this repository, so the two move together. Overrides are ignored by consumers, so this does not affect anyone depending on the published package. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCmKSRuHNETmfGu2TffVzo
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.
Adds
CancellationTokensupport for in-flight downloads, rebased onto the upstream sync and dependency upgrade from #2 (now merged intodevelop).Replaces #3, which GitHub auto-closed when #2's branch was deleted — a closed PR whose base branch is gone cannot be reopened or retargeted. Same branch, same commits.
Changes
CancellationTokenis threaded throughFileService.get,WebHelper,CacheManager,ImageCacheManagerandFirebaseHttpFileService.Rebasing onto the upgraded base produced conflicts in six files. Every one was upstream's
dart formatreflow against the feature's added parameter, with no semantic upstream change to any of them — verified by checking that each file was touched upstream only by theformatted files/Format ... with dart formatcommits. Resolved by taking the feature side and re-runningdart format.Two commits on top of the original work:
test/mock.mocks.dartregenerated against mockito 5.8.1dart formatapplied to the cancellation sources, which CI enforcesVerification
On Flutter 3.47.1 / Dart 3.13.1:
flutter analyze— No issues foundflutter test— 113 passed (107 from the base plus 6 cancellation tests)dart format --set-exit-if-changed .— cleanThe net diff against
developtouches the same 10 files as the original pre-rebase feature diff. Merges cleanly intodevelop(verified locally).🤖 Generated with Claude Code
https://claude.ai/code/session_01TCmKSRuHNETmfGu2TffVzo