This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-10
Channels
- # aleph (3)
- # announcements (1)
- # architecture (16)
- # bangalore-clj (1)
- # beginners (65)
- # biff (5)
- # calva (23)
- # clj-kondo (6)
- # clj-otel (12)
- # clojure-austin (2)
- # clojure-europe (11)
- # clojure-norway (7)
- # clojure-uk (1)
- # clojuredesign-podcast (2)
- # clojurescript (18)
- # conjure (3)
- # datomic (1)
- # deps-new (18)
- # events (1)
- # hyperfiddle (14)
- # java (4)
- # malli (5)
- # off-topic (10)
- # pathom (13)
- # polylith (10)
- # practicalli (1)
- # re-frame (3)
- # reitit (16)
- # releases (1)
- # rum (5)
- # shadow-cljs (17)
Isn’t there a trick or caveat to handling exceptions in cljs go blocks? I seem to recall they can be silently swallowed if it isn’t done right.
And once I’ve used <p!
inside a go
block to get the value of a function that returns a Promise, how can I access that value returned from the go
block? It doesn’t look like cljs has a <!!
macro for use outside go
blocks.
That's correct. go
returns a channel and you must either pass that channel around till you eventually get a value from it in another go
block or simply remain in the same go
block.
Same deal with promises. You can either keep on chaining .then
right there where you got the promise or you can pass it somewhere else and call .then
there. You can't just get the value.
Hmm. So if the function returns a promise and I need to return that value, what’s the best way to do it? Or I should say if I need to use that value?
I discovered take! About an hour ago, so I’m going to experiment with it but so far it’s not returning the value I expect or I should say it’s not logging to the console the value that I expect
You can't return the value.
You can make the promise deliver the value to some other function.
And just in case - if all you're using core.async
for is getting values from promises, then don't. Just use promises, without core.async
- much simpler that way.
I guess I could do some thing like setting an atom and then waiting for it to be populated but that seems really kludgy
I think you’re right I just need to stick with chaining the promises as usual
Nothing in the JS world that's async will simply return a value.
It will always return a promise or something similar. Even the JS's await
is just sugar around promises.
I used to have fun with this in Scala and it always drove me crazy lol. Flat map everything.
Scala futures
I think take!
would do the trick, but I’ll stick with chaining. Good suggestion.
Yeah that’s what I’ll do. Basically a call back.
If you like some simple helpers for promises there is also https://github.com/funcool/promesa
I enjoy it a lot. Especially p/let
I’ve heard good things about it as well