emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/with-url 5bd8812 4/8: Make :wait case actually wor


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] scratch/with-url 5bd8812 4/8: Make :wait case actually work.
Date: Sun, 22 Jan 2017 00:29:33 +0000 (UTC)

branch: scratch/with-url
commit 5bd88122094f7c8f25976e9a32772f213995b86f
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Make :wait case actually work.
---
 lisp/url/with-url.el |   37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/lisp/url/with-url.el b/lisp/url/with-url.el
index cce68bc..d3a75b6 100644
--- a/lisp/url/with-url.el
+++ b/lisp/url/with-url.el
@@ -171,13 +171,14 @@ and `base64'."
        ,(if wait
             `(progn
                (with-url--wait ,requestv)
-               (let ((buffer (current-buffer)))
-                 (unwind-protect
-                     (when (or (not (url-request-ignore-errors req))
-                               (url-okp))
-                       (goto-char (point-min))
-                       ,@body)
-                   (kill-buffer buffer))))
+               (let ((buffer (process-buffer (url-request-process ,requestv))))
+                 (with-current-buffer buffer
+                   (unwind-protect
+                       (when (or (not (url-request-ignore-errors ,requestv))
+                                 (url-okp))
+                         (goto-char (point-min))
+                         ,@body)
+                     (kill-buffer buffer)))))
           `(progn
              (setf (url-request-callback ,requestv)
                    (lambda ()
@@ -285,9 +286,10 @@ If given, return the value in BUFFER instead."
       (when (or (not (url-request-ignore-errors req))
                 (url-okp))
         (goto-char (point-min))
-        (unwind-protect
-            (funcall (url-request-callback req))
-          (kill-buffer buffer))))))
+        (when (url-request-callback req)
+          (unwind-protect
+              (funcall (url-request-callback req))
+            (kill-buffer buffer)))))))
 
 (defun with-url--timer (req)
   (let ((now (float-time)))
@@ -509,7 +511,6 @@ If given, return the value in BUFFER instead."
       (with-url--callback process)))))
 
 (defun with-url--callback (process &optional status)
-  (message "Calling back")
   (let ((req (plist-get (process-plist process) :request))
         (buffer (process-buffer process)))
     ;; Pass the https certificate on to the caller.
@@ -547,9 +548,10 @@ If given, return the value in BUFFER instead."
           (forward-char -1)
           (delete-char -1)))
       (goto-char (point-min))
-      (unwind-protect
-          (funcall (url-request-callback req))
-        (kill-buffer buffer)))))
+      (when (url-request-callback req)
+        (unwind-protect
+            (funcall (url-request-callback req))
+          (kill-buffer buffer))))))
 
 (defun with-url--decode-chunked ()
   (let (length)
@@ -622,9 +624,10 @@ If given, return the value in BUFFER instead."
     with-url--headers))
 
 (defun with-url--wait (req)
-  (with-url--fetch req)
-  (while (not (url-request-finished req))
-    (sleep-for 0.1)))
+  (prog1
+      (with-url--fetch req)
+    (while (not (url-request-finished req))
+      (sleep-for 0.1))))
 
 (provide 'with-url)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]