Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b0c57f

Browse files
Merge pull request #341 from SDWebImage/bugfix/progress_block_data_race
Fix the data race because progress block is called in non-main queue
2 parents 6c27d02 + 46407f9 commit 0b0c57f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

‎SDWebImageSwiftUI/Classes/ImageManager.swift‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public final class ImageManager : ObservableObject {
8585
self.indicatorStatus.isLoading = true
8686
self.indicatorStatus.progress = 0
8787
currentOperation = manager.loadImage(with: url, options: options, context: context, progress: { [weak self] (receivedSize, expectedSize, _) in
88+
// This block may be called in non-main thread
8889
guard let self = self else {
8990
return
9091
}
@@ -95,7 +96,11 @@ public final class ImageManager : ObservableObject {
9596
progress = 0
9697
}
9798
self.indicatorStatus.progress = progress
98-
self.progressBlock?(receivedSize, expectedSize)
99+
if let progressBlock = self.progressBlock {
100+
DispatchQueue.main.async {
101+
progressBlock(receivedSize, expectedSize)
102+
}
103+
}
99104
}) { [weak self] (image, data, error, cacheType, finished, _) in
100105
guard let self = self else {
101106
return

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /