Skip to content

Commit

Permalink
Make callbacks in ImagePipeline sendable
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jul 7, 2024
1 parent a15c5f5 commit 213ca67
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Sources/Nuke/Pipeline/ImagePipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public final class ImagePipeline: @unchecked Sendable {
/// is finished.
@discardableResult public func loadImage(
with url: URL,
completion: @escaping (_ result: Result<ImageResponse, Error>) -> Void
completion: @Sendable @escaping (_ result: Result<ImageResponse, Error>) -> Void
) -> ImageTask {
loadImage(with: ImageRequest(url: url), queue: nil, progress: nil, completion: completion)
}
Expand All @@ -175,7 +175,7 @@ public final class ImagePipeline: @unchecked Sendable {
/// is finished.
@discardableResult public func loadImage(
with request: ImageRequest,
completion: @escaping (_ result: Result<ImageResponse, Error>) -> Void
completion: @Sendable @escaping (_ result: Result<ImageResponse, Error>) -> Void
) -> ImageTask {
loadImage(with: request, queue: nil, progress: nil, completion: completion)
}
Expand All @@ -193,8 +193,8 @@ public final class ImagePipeline: @unchecked Sendable {
@discardableResult public func loadImage(
with request: ImageRequest,
queue: DispatchQueue? = nil,
progress: ((_ response: ImageResponse?, _ completed: Int64, _ total: Int64) -> Void)?,
completion: @escaping (_ result: Result<ImageResponse, Error>) -> Void
progress: (@Sendable (_ response: ImageResponse?, _ completed: Int64, _ total: Int64) -> Void)?,
completion: @Sendable @escaping (_ result: Result<ImageResponse, Error>) -> Void
) -> ImageTask {
loadImage(with: request, queue: queue, progress: {
progress?($0, $1.completed, $1.total)
Expand All @@ -205,8 +205,8 @@ public final class ImagePipeline: @unchecked Sendable {
with request: ImageRequest,
isDataTask: Bool = false,
queue callbackQueue: DispatchQueue?,
progress: ((ImageResponse?, ImageTask.Progress) -> Void)?,
completion: @escaping (Result<ImageResponse, Error>) -> Void
progress: (@Sendable (ImageResponse?, ImageTask.Progress) -> Void)?,
completion: @Sendable @escaping (Result<ImageResponse, Error>) -> Void
) -> ImageTask {
makeStartedImageTask(with: request, isDataTask: isDataTask) { [weak self] event, task in
self?.dispatchCallback(to: callbackQueue) {
Expand All @@ -225,7 +225,7 @@ public final class ImagePipeline: @unchecked Sendable {
}
}

private func dispatchCallback(to callbackQueue: DispatchQueue?, _ closure: @escaping () -> Void) {
private func dispatchCallback(to callbackQueue: DispatchQueue?, _ closure: @Sendable @escaping () -> Void) {
if callbackQueue === self.queue {
closure()
} else {
Expand All @@ -237,7 +237,7 @@ public final class ImagePipeline: @unchecked Sendable {

/// Loads image data for the given request. The data doesn't get decoded
/// or processed in any other way.
@discardableResult public func loadData(with request: ImageRequest, completion: @escaping (Result<(data: Data, response: URLResponse?), Error>) -> Void) -> ImageTask {
@discardableResult public func loadData(with request: ImageRequest, completion: @Sendable @escaping (Result<(data: Data, response: URLResponse?), Error>) -> Void) -> ImageTask {
loadData(with: request, queue: nil, progress: nil, completion: completion)
}

Expand All @@ -257,8 +257,8 @@ public final class ImagePipeline: @unchecked Sendable {
@discardableResult public func loadData(
with request: ImageRequest,
queue: DispatchQueue? = nil,
progress progressHandler: ((_ completed: Int64, _ total: Int64) -> Void)?,
completion: @escaping (Result<(data: Data, response: URLResponse?), Error>) -> Void
progress progressHandler: (@Sendable (_ completed: Int64, _ total: Int64) -> Void)?,
completion: @Sendable @escaping (Result<(data: Data, response: URLResponse?), Error>) -> Void
) -> ImageTask {
loadImage(with: request, isDataTask: true, queue: queue) { _, progress in
progressHandler?(progress.completed, progress.total)
Expand Down Expand Up @@ -408,7 +408,7 @@ public final class ImagePipeline: @unchecked Sendable {

// Deprecated in Nuke 12.7
@available(*, deprecated, message: "Please the variant variant that accepts `ImageRequest` as a parameter")
@discardableResult public func loadData(with url: URL, completion: @escaping (Result<(data: Data, response: URLResponse?), Error>) -> Void) -> ImageTask {
@discardableResult public func loadData(with url: URL, completion: @Sendable @escaping (Result<(data: Data, response: URLResponse?), Error>) -> Void) -> ImageTask {
loadData(with: ImageRequest(url: url), queue: nil, progress: nil, completion: completion)
}

Expand Down

0 comments on commit 213ca67

Please sign in to comment.