Fork me on GitHub
#clojurescript
<
2021-08-21
>
zendevil.eth05:08:45

is <p! blocking in clojurescript?

zendevil.eth05:08:07

Does it wait for the promise to resolve before evaluating the next expression?

p-himik05:08:38

It does, but it's not blocking. It parks instead of blocking.

zendevil.eth06:08:15

what’s the difference between parking and blocking?

zendevil.eth06:08:03

(<p! (some-promise))
(prn (+ 7 7))
does prn wait for the promise to resolve?

p-himik06:08:20

Blocking blocks - there's no more execution. Well, maybe in other threads on other platforms, but JS doesn't have them. Parking doesn't block - it allows for the execution to continue elsewhere. The second line of code above won't be executed till the promise is resolved, but some other code outside of that go block might be executed.

p-himik06:08:12

In other words, <p! blocks the current go block.

kennytilton21:08:13

I asked this over on #cljsrn on the off chance this was sth about RN JS, but no ideas yet: Got a dummy interop Q here: what on Earth is #object[String]? Using the cljs-http example:                   (http/get "https://api.github.com/users"                                       {:with-credentials? false                                        :query-params      {"since" 135}}) I pull the users as suggested with: (map :login (:body response)) Looks great, except when I offer the first as the title of a Button (have not figured out Text yet, of all things), ReactNative complains: "Invariant Violation: The title prop of a Button must be a string" So I print out the type and sure enough it is #object[String]. js->clj does not help. str works, but I do not get why: (type (str etc)) also returns #object[String]! Weirdly, if I (map str (map :login etc)) as soon as I get the response, I still have to call str when passing the first username as the title! So...what on Earth is #object[String]?! The Google is silent, tho with tons of hits on translating key-value kinda objects. I started thinking it might be how a JSON object might be presented in the reader, but got nowhere with that idea. btw, I can use goog.object to get all the keys: length, 1,2,3... 🙂 object[String] aside, I am exploring having cljs-http convert the response to a clojure map (if there is such a feature). But that would be an ugly way out. I had the same thought about having goog.object parse the response before I got down to an individual object[String]: ugly.

alpox23:08:18

May be a RN thing in the end? I tried this with ClojureScript in the browser and get normal strings :thinking_face:

alpox23:08:37

Now I'm kind of confused about your statement of: > I am exploring having cljs-http convert the response to a clojure map (if there is such a feature). Because it seems thats what I get back from cljs-http when doing this request in the first place :thinking_face:

kennytilton00:08:22

Yeah, @U6JS7B99S, it is tough looking at print output and understanding what is going on. Turns out the map values are all ValSeq's: https://cljs.github.io/api/cljs.core/ValSeq. Looks like I need to call the toString method on one to get a Clojure string. googles Clojure records

kennytilton01:08:23

OK, haha, this was the other direction of interop: converting CLJ ValSeq to JS to make RN happy, and even funnier, str is exactly how to convert a ValSeq to a string RN will like.

colinkahn04:08:49

Maybe you've already found this, but I think this might be a someone instantiating a String vs using a string literal, which has some differences

sova-soars-the-sora15:08:01

I think I had to use cljs.reader/read-string for a similar issue. I think I also added :type :text to the keys in the http/get map... Did you resolve your issue?

kennytilton17:08:36

Yes, @U3ES97LAC, thanks. I guess cljs-http is creating the ValSeq strings. Anyway. all I needed was a way to pass the string value to RN as the title of the button, and the Helix doc makes clear that I have to take care of that, not Helix. The funny thing is I had succeeded with (str my-val-seq) early on but thought that was a hack, a failure to interop. 🙂 It was, but not what I thought: converting from JS. With str I converted /to/ a string JS could handle, and str (via toString) is the preferred method for converting ValSeq to a str. It just took me six hours to figure that out. 🙂

sova-soars-the-sora17:08:58

😅 i think it took me a couple months to find out about cljs.reader/read-string so you're doing great at just a quarter of a day.

kennytilton13:08:40

haha, you know, I tried read-string, that did not work for me. I think right about there is where I pulled down the cljs-http source and tracked down ValSeq. That is when I realized I was dealing with a reverse interop issue!