From 970c28e7c19f075704eb921b125f1da969abf882 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 16 Nov 2026 08:08:00 -0800 Subject: [PATCH] =?UTF-8?q?Refill=20web=20view=20pool=20synchronously=20so?= =?UTF-8?q?=20pending=20dequeue=20doesn=E2=80=99t=20hit=20an=20empty=20que?= =?UTF-8?q?ue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/Article/WebViewProvider.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/iOS/Article/WebViewProvider.swift b/iOS/Article/WebViewProvider.swift index a592f9fb2..396f63afa 100644 --- a/iOS/Article/WebViewProvider.swift +++ b/iOS/Article/WebViewProvider.swift @@ -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() } }