mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 13:33:42 +00:00
VideoThumbnails: retry 3 times fetching from URL
Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
parent
a194738bb6
commit
c9ce574c7a
@ -5,10 +5,27 @@ final class ThumbnailsModel: ObservableObject {
|
|||||||
static var shared = ThumbnailsModel()
|
static var shared = ThumbnailsModel()
|
||||||
|
|
||||||
@Published var unloadable = Set<URL>()
|
@Published var unloadable = Set<URL>()
|
||||||
|
private var retryCounts = [URL: Int]()
|
||||||
|
private let maxRetries = 3
|
||||||
|
private let retryDelay: TimeInterval = 0.25
|
||||||
|
|
||||||
func insertUnloadable(_ url: URL) {
|
func insertUnloadable(_ url: URL) {
|
||||||
DispatchQueue.main.async {
|
let retries = (retryCounts[url] ?? 0) + 1
|
||||||
self.unloadable.insert(url)
|
|
||||||
|
if retries >= maxRetries {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.unloadable.insert(url)
|
||||||
|
self.retryCounts.removeValue(forKey: url)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.retryCounts[url] = retries
|
||||||
|
}
|
||||||
|
DispatchQueue.global().asyncAfter(deadline: .now() + retryDelay) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.retryCounts[url] = retries
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user