Skip to content

Commit

Permalink
weak
Browse files Browse the repository at this point in the history
  • Loading branch information
Amol Prabhu committed Aug 8, 2024
1 parent e97d20a commit bb489fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Sources/Nuke/Tasks/TaskFetchOriginalData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
})
Expand Down
9 changes: 6 additions & 3 deletions Sources/Nuke/Tasks/TaskFetchWithPublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
}
Expand All @@ -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)
}
})
Expand Down

0 comments on commit bb489fe

Please sign in to comment.