Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start ImageTask in .suspended state #844

Merged
merged 7 commits into from
Apr 6, 2025
Merged

Conversation

kean
Copy link
Owner

@kean kean commented Apr 6, 2025

No description provided.

@@ -152,26 +151,33 @@ public final class ImageTask: Hashable {
self.isDataTask = isDataTask
self.pipeline = pipeline
self.onEvent = onEvent
// TODO: remove thread hop
self.task = Task { @ImagePipelineActor in
Copy link
Owner Author

@kean kean Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImageTask is created from a nonisolated method (by design), which previously required to spawn a Task to perform it. By delaying the task start until you call one of its async APIs such as response: ImageResponse, we can take advantage of the asynchronous context created by however invokes it. There is no need to spawn one of our own. This eliminates a thread hop.

/// The task is currently running.
case running
/// The task has received a cancel message.
case cancelled
/// The task has completed (without being canceled).
case completed
case completed(Result<ImageResponse, Error>)
Copy link
Owner Author

@kean kean Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It no longer relies on Task caching of results.

@kean kean merged commit 65ce078 into nuke13 Apr 6, 2025
1 of 7 checks passed
@kean kean deleted the task/image-task-in-suspended-state branch April 6, 2025 22:46
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