This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-12
Channels
- # aleph (10)
- # beginners (79)
- # boot (81)
- # chestnut (3)
- # cider (9)
- # cljs-dev (336)
- # cljsrn (17)
- # clojure (121)
- # clojure-boston (1)
- # clojure-italy (4)
- # clojure-nl (1)
- # clojure-russia (218)
- # clojure-spec (32)
- # clojure-uk (98)
- # clojurescript (109)
- # cloverage (1)
- # core-async (5)
- # cursive (17)
- # datascript (15)
- # datomic (38)
- # editors (4)
- # emacs (6)
- # graphql (1)
- # hoplon (140)
- # instaparse (1)
- # jobs (2)
- # klipse (1)
- # leiningen (4)
- # lumo (2)
- # mount (103)
- # off-topic (3)
- # om (8)
- # onyx (19)
- # parinfer (32)
- # pedestal (3)
- # precept (32)
- # re-frame (33)
- # reagent (24)
- # remote-jobs (11)
- # rum (1)
- # spacemacs (1)
- # specter (37)
- # unrepl (4)
- # untangled (43)
- # vim (11)
It’s pretty wet in Surrey too
from ☀️ north east england
I think I've eventually finished filling in forms for my next contract...until I start...then I'll probably have a lot more to fill in!
gawd that looks just awfully depresseing @maleghast , how do you stand it ?
@maleghast looks terrible...I'd just like to find a role within 250 miles of my house atm!
@agile_geek - Well, that I can relate to as technically__ my role is London based, but I am being allowed to work remotely full time at the moment and into the Autumn I will be back to London 3 days, Trossachs 4 days 😉
Looks like I'm doomed to spend 5 days per week away from home for at least another 3 months
Sorry to hear that mon ami - I did that every other week for a while when we were in the Philippines, going to Hong Kong, and it was no fun… 😞
OK… I am trying to get data from an API using the http-kit client… It seems__ as though the promise that I get back from the function is NEVER fulfilled… What have I missed (please - tearing my hair out at this point):
(defn rightrelevance-request
"Function to request content from RightRelevance API"
[terms start rows access_token]
(http/request
{:url ""
:method :get
:user-agent "Cervest Harvester"
:query-params {"query" terms
"start" start
"rows" rows
"access_token" access_token}}
(fn [{:keys [status headers body error]}] ;; asynchronous response handling
(if error
(println "Failed, exception is " error)
(println "Async HTTP GET: " status)))))
(is it because I am evaluating a call to this function in my emacs buffer and for some reason that can’t wait for the response?)
@maleghast are you specifying a callback and expecting a result in the response promise ?
This part:
(fn [{:keys [status headers body error]}] ;; asynchronous response handling
(if error
(println "Failed, exception is " error)
(println "Async HTTP GET: " status)))
is the callback, as per the http-kit documentationi've not used http-kit much, but using both (callback and promise) seems a bit unusual
does your callback get called?
That’s the “instructions” I am following… I am assuming that I have either missed something OR they are assuming that I know something that I don’t… 😞
(my options map is just inside the function instead of being def-ed outside and passed in)
ah, i see, it delivers the result of your callback to the promise - https://github.com/http-kit/http-kit/blob/master/src/org/httpkit/client.clj#L197
so if your callback is never getting called then you will never get a response - it looks like your http request is not returning for some reason
do you get a response if you curl the url ?
http-kit doesn't appear to have any useful logging in the java part of the client https://github.com/http-kit/http-kit/blob/master/src/java/org/httpkit/client/HttpClient.java
Ah, no I don’t any more… I just re-ran my test cURL (admittedly using a client - Insomnia) and that no longer works…
What I do get back is this: #object[clojure.core$promise$reify__9424 0x5c770e66 {:status :pending, :val nil}]
yeah, that's just the default response promise from here https://github.com/http-kit/http-kit/blob/master/src/org/httpkit/client.clj#L186
ahahaha
hmm - your callback is returning nil, which would lead to a nil response, though i would have expected the status to not be :pending
what happens if you just remove your callback ?
@mccraigmccraig I just get the promise back in a pending state
@maleghast have you derefed it after that ?
@glenjamin - I have done that too - never got anything other than pending
it's expected that you should get the promise back :pending
immediately - and that the value should be delivered some time later
how about a different url @maleghast ?
I’ve taken the callback out and now I get this when I deref the promise:
{:opts {:url "", :method :get, :user-agent "Cervest Harvester", :query-params {"query" "agriculture climate change", "start" 0, "rows" 10, "access_token" "998647ad406b2870b6a738e0243db376f8daf6a05175fc2d4d164e43f257882e"}}, :body "", :headers {:connection "keep-alive", :content-length "0", :date "Wed, 12 Jul 2017 12:49:30 GMT"}, :status 500}
so that's working now
your callback was returning nil
and the value of the callback is what gets delivered to the promise
so your callback would never deliver anything other than nil
@mccraigmccraig - Ok, I get that… http-kit REALLY need to update their docs in that case…
but deliver
works perfectly well with a nil
value, so i can't see why your original response wouldn't have looked like : #promise[{:status :ready, :val nil} 0x2e7c756]
whereas @maleghast 's original promise :status
was :pending
So, once I’ve got the API’s curator to fix their 500, how do I write a bit of code that derefs the promise once it’s been fulfilled?
more abstract question @maleghast - what are you planning on doing with http-kit ? plain clojure promise
s are a poor async abstraction
@mccraigmccraig - I am using it as an HTTP client to get data from an API
(because they don't support callbacks, so composition (aka doing something with the result) is not easy without blocking)
the responses - if 200s with bodies - will be parsed, put into a canonical DB and added to an ES index.
Nothing needs to be in real-time and nothing will be blocking clients to the app, as they will get their results from the ES cluster and will be ok with potentially old / stale data.
if you don't mind blocking then plain clj promise
s will do fine... if you want to avoid blocking then https://github.com/ztellman/aleph is much easier, or you could use the http-kit callback to put results on a core.async chan
there’s a small learning curve around manifold with aleph, but I’ve found it to be pretty nice when I’ve used it
i'm a manifold+aleph fanboy, so i'm probably biased
Hehe - nothing wrong with liking library-x over library-y - at least you know your biases @mccraigmccraig
actually, i'm a cats+manifold+aleph fanboy - together those things are great
I am wondering what the benefit is in using it over http-kit in my current use-case…
no benefit if you will be immediately blocking on the response promise
if you want to experiment with making something entirely non-blocking though, aleph/manifold will be much better - https://github.com/ztellman/manifold/blob/master/docs/deferred.md#composing-with-deferreds
Ok, so I how do I kill the REPL in my emacs (cider-connect) from outside - my emacs is completely blocked - the API that I am trying to use is having problems and the REPL is completely blocked and locked up.
ctrl-c ctrl-c
not working ?
@maleghast you can try and kill -SIGUSR2
the emacs process
No worries, I’ve had spacemacs
freeze due to some helm
bug and i’ve used it a few times
Just a thought from the sun bed: how can you lint clojure? Example rule: it's nonsensical to call =
with one parameter (although valid) usually you've made a mistake.
However, searching the code for (= elem)
will catch:
(-> x
(= 10))
Well, you say, run it after macro expansion!
But what about the numerous macros that might generate that code? Cond variants are perhaps candidates for this. I know eastwood hates:
(cond-> 10
true
Inc
Foo?
Inc)
Because the generated code contains an always true check (`(if true ...)`)