emacs-deferred
emacs-deferred copied to clipboard
Correct way of making parallel http post requests
Hi, I am trying to make a number of concurrent http post requests from inside emacs. The deferred:parallel function seems perfect for this task however I cannot get it to work.
I have an example function with three requests being made bellow. I would like them to all complete asynchronously in parallel and then return the result as a list in the deferred:nextc function so I can operate on them.
(defun my-deferred-func ()
(let ((lk ))
(deferred:$
(deferred:parallel
(request (format "http://localhost:%s" tern-known-port)
:type "POST"
:parser 'json-read
:success (function* (lambda (&key data &allow-other-keys)
(push (cdr (car data)) lk)))
:data
(format "{\"query\":{\"end\":%s,\"file\":\"%s\",\"type\":\"type\",\"preferFunction\":true}}"
196
(buffer-file-name)
)
:sync nil)
(request (format "http://localhost:%s" tern-known-port)
:type "POST"
:parser 'json-read
:success (function* (lambda (&key data &allow-other-keys)
(push (cdr (car data)) lk)))
:data
(format "{\"query\":{\"end\":%s,\"file\":\"%s\",\"type\":\"type\",\"preferFunction\":true}}"
196
(buffer-file-name)
)
:sync nil)
(request (format "http://localhost:%s" tern-known-port)
:type "POST"
:parser 'json-read
:success (function* (lambda (&key data &allow-other-keys)
(push (cdr (car data)) lk)))
:data
(format "{\"query\":{\"end\":%s,\"file\":\"%s\",\"type\":\"type\",\"preferFunction\":true}}"
196
(buffer-file-name)
)
:sync nil)
)
(deferred:nextc it (lambda (args) args))
)))
The above requests make a simple post request to the ternjs server.
Any guidance on using deferred:parallel? I have also seen the deferred:url-post but having trouble wrapping my head around that function too.