Fork me on GitHub
#clojurescript
<
2019-10-21
>
Filipe Silva13:10:05

heya, a question please: What's the idiomatic CLJS way of interacting with promises? https://github.com/athos/kitchen-async offers something that looks pretty ok:

(require '[kitchen-async.promise :as p])

(p/let [browser (puppeteer/launch)
        page (.newPage browser)]
  (.goto page "")
  (.screenshot page #js{:path "screenshot.png"})
  (.close browser))
But I imagine there a similar way of doing this with core.async. I'm just having a lot of trouble finding a good example of it.

mhuebert19:10:21

I really like kitchen-async, and wouldn’t see an advantage of using core.async in its place

👍 4
Filipe Silva19:10:55

ok, that seems to be the overall sentiment for these cases

dominicm13:10:10

Using thread-first and interop works very well.

Filipe Silva13:10:09

can you give me an example of how the code above would look like in the style you suggest please?

Roman Liutikov13:10:06

(-> (js/fetch url)
  (.then #(println %))
  (.catch #(println %)))

Roman Liutikov13:10:43

but that’s for a chain of then

Roman Liutikov13:10:01

with cases like Puppeteer a chain of promises would look less readable, so something like p/let should be fine

Filipe Silva13:10:03

and core.async doesn't really cover the single output case very well, I take it?

borkdude15:10:51

You can also write a thenP and catchP macro which take a promise as the first arg and wrap the rest of the args in an anonymous function body.

borkdude15:10:59

if you're into sugar 🙂

martinklepsch15:10:53

Instead of kitchen-async also consider promesa, it’s a bit better maintained (proper releases/changelog) IMHO — on the flipside it lacks some macro sugar that you may like or not like (e.g. promise aware threading macros)

Filipe Silva15:10:27

yes I had tried promesa already and was default to it, just wanted to know if I was missing something really obvious wrt core.async

martinklepsch15:10:14

I think the current community “thinking” wrt core.async is that it is very powerful and can do many amazing things but that 99% of the time you don’t need these amazing things and a more basic abstraction like promises are actually perfectly fine.

20
Filipe Silva18:10:31

that description makes me feel a lot better, thank you 🙂

martinklepsch19:10:45

my pleasure 🙂

dominicm13:10:30

I'd recommend starting with that until you start to feel pain

e13:10:43

How might I get permissions to report a bug on the CLJS Jira? It tells me I don't have access after creating an account. I tracked down a bug where it hits an internal "not an absolute path" error about closure type external JS libs.

e13:10:57

Is that really required for just a bug report?

e13:10:07

It talks about code contributions.

dominicm13:10:25

No. I don't think so.

Alex Miller (Clojure team)13:10:44

yes, please file a question at ask.clojure and tag it with problem

Alex Miller (Clojure team)13:10:56

once triaged, a dev can file a jira

e13:10:38

Thanks, I'll do that. https://clojurescript.org/community/reporting-issues should be updated to say this I think 🙂

Alex Miller (Clojure team)13:10:26

yeah, I've updated all the clojure docs but haven't gotten to cljs. added to my list for today