Skip to content

Network request cancellation (rebased onto the upstream sync) - #4

Merged
ben-milanko merged 8 commits into
developfrom
feat/network-request-cancellation-2
Sep 5, 2026
Merged

ben-milanko merged 8 commits into
developfrom
feat/network-request-cancellation-2

Conversation

@ben-milanko

Copy link
Copy Markdown

Adds CancellationToken support for in-flight downloads, rebased onto the upstream sync and dependency upgrade from #2 (now merged into develop).

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

CancellationToken is threaded through FileService.get, WebHelper, CacheManager, ImageCacheManager and FirebaseHttpFileService.

Rebasing onto the upgraded base produced conflicts in six files. Every one was upstream's dart format reflow 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 the formatted files / Format ... with dart format commits. Resolved by taking the feature side and re-running dart format.

Two commits on top of the original work:

  • test/mock.mocks.dart regenerated against mockito 5.8.1
  • dart format applied to the cancellation sources, which CI enforces

Verification

On Flutter 3.47.1 / Dart 3.13.1:

  • flutter analyze — No issues found
  • flutter test — 113 passed (107 from the base plus 6 cancellation tests)
  • dart format --set-exit-if-changed . — clean

The net diff against develop touches the same 10 files as the original pre-rebase feature diff. Merges cleanly into develop (verified locally).

🤖 Generated with Claude Code

https://claude.ai/code/session_01TCmKSRuHNETmfGu2TffVzo

ben-milanko and others added 7 commits September 5, 2026 14:01
- 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
@ben-milanko
ben-milanko merged commit e11dab1 into develop Sep 5, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant