+ (if (not (gnus-buffer-live-p summary))
+ (gnus-async-with-semaphore
+ (setq gnus-async-fetch-list nil))
+ (when (and gnus-asynchronous
+ (gnus-alive-p))
+ (when next
+ (gnus-async-with-semaphore
+ (pop gnus-async-fetch-list)))
+ (let ((do-fetch next)
+ (do-message t)) ;(eq major-mode 'gnus-summary-mode)))
+ (when (and (gnus-group-asynchronous-p group)
+ (gnus-buffer-live-p summary)
+ (or (not next)
+ gnus-async-fetch-list))
+ (gnus-async-with-semaphore
+ (unless next
+ (setq do-fetch (not gnus-async-fetch-list))
+ ;; Nix out any outstanding requests.
+ (setq gnus-async-fetch-list nil)
+ ;; Fill in the new list.
+ (let ((n gnus-use-article-prefetch)
+ (data (gnus-data-find-list article))
+ d)
+ (while (and (setq d (pop data))
+ (if (numberp n)
+ (natnump (decf n))
+ n))
+ (unless (or (gnus-async-prefetched-article-entry
+ group (setq article (gnus-data-number d)))
+ (not (natnump article))
+ (not (funcall gnus-async-prefetch-article-p d)))
+ ;; Not already fetched -- so we add it to the list.
+ (push article gnus-async-fetch-list)))
+ (setq gnus-async-fetch-list
+ (nreverse gnus-async-fetch-list))))
+
+ (when do-fetch
+ (setq article (car gnus-async-fetch-list))))
+
+ (when (and do-fetch article)
+ ;; We want to fetch some more articles.
+ (with-current-buffer summary
+ (let (mark)
+ (gnus-async-set-buffer)
+ (goto-char (point-max))
+ (setq mark (point-marker))
+ (let ((nnheader-callback-function
+ (gnus-make-async-article-function
+ group article mark summary next))
+ (nntp-server-buffer
+ (get-buffer gnus-async-prefetch-article-buffer)))
+ (when do-message
+ (gnus-message 9 "Prefetching article %d in group %s"
+ article group))
+ (setq gnus-async-current-prefetch-group group)
+ (setq gnus-async-current-prefetch-article article)
+ (gnus-request-article article group))))))))))
+
+(defun gnus-make-async-article-function (group article mark summary next)
+ "Return a callback function."
+ `(lambda (arg)
+ (gnus-async-article-callback arg ,group ,article ,mark ,summary ,next)))
+
+(eval-when-compile
+ (autoload 'gnus-html-prefetch-images "gnus-html"))
+
+(defun gnus-async-article-callback (arg group article mark summary next)
+ "Function called when an async article is done being fetched."
+ (save-excursion
+ (setq gnus-async-current-prefetch-article nil)
+ (when arg
+ (gnus-async-set-buffer)