(require 'url-http)(require 'url-parse)
(defun url-retrieve-thread (url)
"Wrapper around url-http that download `URL' without blocking main thread."
(let* ((parsed-url (if (url-p url) url (url-generic-parse-url url)))
(mut (make-mutex))
(cond-var (make-condition-variable mut))
(buf nil)
(cb (lambda (&rest _) (setq buf (current-buffer)) (with-mutex mut (condition-notify cond-var)) )) )
(url-http parsed-url cb nil)
(with-mutex mut
(condition-wait cond-var) )
buf))
Idea was to call it from thread. In most trivial case:
(make-thread (apply 'url-retrieve-thread "http://example.com" nil))
It makes Emacs unresponsive (even C-g does not work).
I tested it on Emacs 28.2 and once of recent development versions (emacs-31.0.50)Happy Hacking!