Skip to content

Commit

Permalink
Make sure that legacy API continues setting state on the callback queue
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed May 7, 2024
1 parent 37a9b70 commit c2720dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Sources/Nuke/ImageTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ public final class ImageTask: Hashable, CustomStringConvertible, @unchecked Send
}

/// Synchronized on `pipeline.queue`.
private func _setState(_ state: State) -> Bool {
func _setState(_ state: State) -> Bool {
guard _state == .running else { return false }
_state = state
withLock { $0.state = state }
if onEvent == nil {
withLock { $0.state = state }
}
return true
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/Nuke/Pipeline/ImagePipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ public final class ImagePipeline: @unchecked Sendable {
case .progress(let value): progress?(nil, value)
case .preview(let response): progress?(response, task.currentProgress)
case .cancelled: break // The legacy APIs do not send cancellation events
case .finished(let result): completion(result)
case .finished(let result):
_ = task._setState(.completed) // Important to do it on the callback queue
completion(result)
}
}
}
Expand Down

0 comments on commit c2720dc

Please sign in to comment.