mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 16:26:04 +00:00
Refill web view pool synchronously so pending dequeue doesn’t hit an empty queue.
This commit is contained in:
1 parent
f28c08c451
commit
970c28e7c1
1 file changed
+9
-3
@@ -36,9 +36,11 @@ import WebKit
|
||||
flushQueue()
|
||||
}
|
||||
|
||||
// Refill synchronously: a dequeue operation may already be pending,
|
||||
// and it must not find the queue empty.
|
||||
private func flushQueue() {
|
||||
queue.removeAllObjects()
|
||||
replenishQueueIfNeeded()
|
||||
WebViewProviderReplenishQueueOperation.fill(queue, articleIconSchemeHandler: articleIconSchemeHandler)
|
||||
}
|
||||
|
||||
func dequeueWebView(completion: @escaping (PreloadedWebView) -> Void) {
|
||||
@@ -48,7 +50,7 @@ import WebKit
|
||||
}
|
||||
|
||||
final class WebViewProviderReplenishQueueOperation: MainThreadOperation, @unchecked Sendable {
|
||||
private let minimumQueueDepth = 3
|
||||
private static let minimumQueueDepth = 3
|
||||
|
||||
private var queue: NSMutableArray
|
||||
private var articleIconSchemeHandler: ArticleIconSchemeHandler
|
||||
@@ -60,12 +62,16 @@ final class WebViewProviderReplenishQueueOperation: MainThreadOperation, @unchec
|
||||
}
|
||||
|
||||
override func run() {
|
||||
Self.fill(queue, articleIconSchemeHandler: articleIconSchemeHandler)
|
||||
didComplete()
|
||||
}
|
||||
|
||||
@MainActor static func fill(_ queue: NSMutableArray, articleIconSchemeHandler: ArticleIconSchemeHandler) {
|
||||
while queue.count < minimumQueueDepth {
|
||||
let webView = PreloadedWebView(articleIconSchemeHandler: articleIconSchemeHandler)
|
||||
webView.preload()
|
||||
queue.insert(webView, at: 0)
|
||||
}
|
||||
didComplete()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user