diff --git a/Sources/Nuke/Tasks/TaskFetchOriginalData.swift b/Sources/Nuke/Tasks/TaskFetchOriginalData.swift index 3e21d66df..b62f8ef7e 100644 --- a/Sources/Nuke/Tasks/TaskFetchOriginalData.swift +++ b/Sources/Nuke/Tasks/TaskFetchOriginalData.swift @@ -54,7 +54,8 @@ final class TaskFetchOriginalData: AsyncPipelineTask<(Data, URLResponse?)> { guard let self else { return finish() } - self.pipeline.queue.async { + self.pipeline.queue.async { [weak self] in + guard let self else { return } self.loadData(urlRequest: urlRequest, finish: finish) } } @@ -83,14 +84,16 @@ final class TaskFetchOriginalData: AsyncPipelineTask<(Data, URLResponse?)> { let dataLoader = pipeline.delegate.dataLoader(for: request, pipeline: pipeline) let dataTask = dataLoader.loadData(with: urlRequest, didReceiveData: { [weak self] data, response in guard let self else { return } - self.pipeline.queue.async { + self.pipeline.queue.async { [weak self] in + guard let self else { return } self.dataTask(didReceiveData: data, response: response) } }, completion: { [weak self] error in finish() // Finish the operation! guard let self else { return } signpost(self, "LoadImageData", .end, "Finished with size \(Formatter.bytes(self.data.count))") - self.pipeline.queue.async { + self.pipeline.queue.async { [weak self] in + guard let self else { return } self.dataTaskDidFinish(error: error) } }) diff --git a/Sources/Nuke/Tasks/TaskFetchWithPublisher.swift b/Sources/Nuke/Tasks/TaskFetchWithPublisher.swift index 16d770c95..7f989cd0f 100644 --- a/Sources/Nuke/Tasks/TaskFetchWithPublisher.swift +++ b/Sources/Nuke/Tasks/TaskFetchWithPublisher.swift @@ -19,7 +19,8 @@ final class TaskFetchWithPublisher: AsyncPipelineTask<(Data, URLResponse?)> { guard let self else { return finish() } - self.pipeline.queue.async { + self.pipeline.queue.async { [weak self] in + guard let self else { return } self.loadData { finish() } } } @@ -40,12 +41,14 @@ final class TaskFetchWithPublisher: AsyncPipelineTask<(Data, URLResponse?)> { let cancellable = publisher.sink(receiveCompletion: { [weak self] result in finish() // Finish the operation! guard let self else { return } - self.pipeline.queue.async { + self.pipeline.queue.async { [weak self] in + guard let self else { return } self.dataTaskDidFinish(result) } }, receiveValue: { [weak self] data in guard let self else { return } - self.pipeline.queue.async { + self.pipeline.queue.async { [weak self] in + guard let self else { return } self.data.append(data) } }) diff --git a/Sources/Nuke/Tasks/TaskLoadImage.swift b/Sources/Nuke/Tasks/TaskLoadImage.swift index b11270537..3e0f9b0be 100644 --- a/Sources/Nuke/Tasks/TaskLoadImage.swift +++ b/Sources/Nuke/Tasks/TaskLoadImage.swift @@ -82,7 +82,8 @@ final class TaskLoadImage: AsyncPipelineTask { ImagePipeline.Error.processingFailed(processor: processor, context: context, error: error) } } - self.pipeline.queue.async { + self.pipeline.queue.async { [weak self] in + guard let self else { return } self.operation = nil self.didFinishProcessing(result: result, isCompleted: isCompleted) } @@ -117,7 +118,9 @@ final class TaskLoadImage: AsyncPipelineTask { let response = signpost(isCompleted ? "DecompressImage" : "DecompressProgressiveImage") { self.pipeline.delegate.decompress(response: response, request: self.request, pipeline: self.pipeline) } - self.pipeline.queue.async { + + self.pipeline.queue.async { [weak self] in + guard let self else { return } self.operation = nil self.didReceiveDecompressedImage(response, isCompleted: isCompleted) }