Unpredictable behavior with drakma-async and cl-async

I am trying to use drakma-asyncin my small project. But I just donโ€™t understand what is happening. (I am using emacs + slime + ccl). I need to get the data using http (s) and parse it in a callback. I assume that I can get incorrect data that cannot be analyzed, so I want to try again. But when I tried to do some tests, I just donโ€™t understand what was going on ...

(defun my-callback (data)
  (prin1 data)
  (restart-case
      (error "Some error parsing data...")
    (just-continue () (prin1 "Continue..."))))

(defun simple-test ()
  (let ((future (asf:make-future)))
    (as:delay #'(lambda () (asf:finish future "Some data")) :time 2)
    (prin1 (asf:future-finished-p future))
    (asf:attach future #'my-callback)))

(defun drakma-test ()
  (asf:alet ((response (das:http-request "http://www.google.com")))
    ;(prin1 (asf:future-finished-p response))
    (asf:attach response #'my-callback)))

(defun drakma-test-let ()
  (let ((response (das:http-request "http://www.google.com")))
    ;(prin1 (asf:future-finished-p response))
    (asf:attach response #'my-callback)))

(defun run-test (test)
  (as:start-event-loop test))

1) So, I will do what I have with my simple example (what I planned)

? (run-test #'simple-test)
NIL"Some data"    ;I get debugger here with simple-error and choose my restart
Invoking restart: #<RESTART JUST-CONTINUE #x7F0578EC20AD>
"Continue..."
1

2) Here is what I get in the second test:

? (run-test #'drakma-test)
"<A LOT OF HTML>
"
1

Where is my debugger and my restart?

3) Uncomment the line ;(prin1 (asf:future...))indrakma-test

? (run-test #'drakma-test)
1

/ bool, , , 1 .

4) , (let ((reponse (das:http-request "http://www.google.com"))) ... ) instad (asf:alet ...) response future, , , response .

? (run-test #'drakma-test-let)
1

5) ;(prin1 (asf:future...)) drakma-test-let

? (run-test #'drakma-test-let)
NIL   ;future is not finished
1

, .

cl-async, , ipv6. , , ... ? ( , , prin1). 5- 5- ?

P.S. drakma-async cl-async . , drakma-async drakma, .

+4
1

m-n, .

, :

:

(defun my-callback (&rest data)
  (format t "Echo from callback: ~A~%" data)
  (restart-case
      (error "Some error parsing data...")
    (just-continue () (prin1 "Continue..."))))

(defun my-errback (e)
  (format t "Echo from errback: ~A~%" e))

(defun make-example-future ()
  (let ((future (asf:make-future))) ;creating future
    (as:delay #'(lambda ()          ;finishing future in 2 seconds
                  (asf:future-handler-case ;wrapping asf:finish
                    (asf:finish future
                                "Result data")
                    (t (e) (asf:signal-error future e)))) ;signal future an error
              :time 2)
    future))

(defun simple-test-2 ()
  (let ((future (make-example-future)))
    (format t "Is future?: ~A~%Finished?: ~A~%"  
            (asf:futurep future) (asf:future-finished-p future))
    (asf:alet ((result future))
      (asf:attach-errback future #'my-errback)
      (format t "Finished? ~A~%" (asf:future-finished-p future))
      (asf:future-finished-p result)
      (asf:attach result #'my-callback))))

:

? (as:start-event-loop #'simple-test-2)
Is future?: T 
Finished?: NIL
;<here we have a 2 sec pause>
Finished? T
Echo from errback: There is no applicable method for the generic function:
#<STANDARD-GENERIC-FUNCTION CL-ASYNC-FUTURE:FUTURE-FINISHED-P #x302001B67A8F>
when called with arguments:
("Result data")

A) asf:alet . , , asf:alet .

B) make-example-future asf:finish asf:future-handler-case asf:signal-error . , , errback. . , (asf:future-finished-p result) future-handler-case, asf:alet ( , ).

C) (asf:future-finished-p result),

Is future?: T
Finished?: NIL
Finished? T
Echo from callback: (Result data) ;here is my data
Echo from errback: Some error parsing data... ;;here is my error
1

drakma-async future-handler-case, asf:finish.

, #2. , asf:alet . errback, . . drakma-test, asf:alet, errback, . http-request let, alet.

#3: (future-finished-p), โ€‹โ€‹ errback.

#4 #5 my-callback: , cl-async , drakma. 7 (, drakma:http-request). , # 4 # 5 , future-hander-case errback.

: , drakma-async future-handler-case, , .

, , - .

+1

All Articles