Improve task cancellation flow & lifecycle management#19
Closed
ThangKM wants to merge 5 commits intoanthony1810:mainfrom
Closed
Improve task cancellation flow & lifecycle management#19ThangKM wants to merge 5 commits intoanthony1810:mainfrom
ThangKM wants to merge 5 commits intoanthony1810:mainfrom
Conversation
…plify ScreenActionStore - CancelBag: auto-remove completed tasks via watch(), add isEmpty/count, accept AnyHashable identifiers, make bag parameter optional - StreamProducer: extract StreamStorage class with deinit cleanup, deprecate nonIsolatedFinish() - ScreenActionStore: replace binding(state:) with receive(action:), add nonisolatedReceive helper with CancelBag support - Add CancelBagTests for auto-removal of completed tasks
…located before completed.
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.
Improve task cancellation flow & lifecycle management
Summary
This PR enhances the cancellation and lifecycle management across
CancelBag,StreamProducer, andScreenActionStore.Changes
CancelBag
watch()method awaits each task's result and removes it from storage upon completion, preventing unbounded growth of the cancellers dictionary.AnyHashableidentifiers — Task identifiers are nowAnyHashableinstead ofString, allowing actions (or anyHashabletype) to be used directly as cancellation keys.store(in:)now accepts an optionalCancelBag?, making it more ergonomic when a cancel bag may not be present.isEmpty/countproperties — Expose the current number of tracked tasks for inspection and testing.StreamProducer
StreamStorage— Moved continuation storage into a dedicatedfinal class StreamStoragewith adeinitthat automatically finishes all streams, ensuring cleanup when the producer is deallocated.nonIsolatedFinish()— Marked as deprecated since streams now auto-finish on deallocation.ScreenActionStore
associatedtype AScreenStateandbinding(state:). The protocol now only requiresreceive(action:).nonisolatedReceive(action:canceller:)— New default extension method that dispatches an action from a nonisolated context, optionally storing the task in aCancelBagusing the action itself as the cancellation identifier.Tests
testWatchTaskCompletedRemoveCancellerFromStorageverifying that completed tasks are automatically removed from the bag.Commit Message