Fork me on GitHub
#shadow-cljs
<
2024-06-05
>
potetm12:06:04

@thheller would you be interested in a pr to allow js-await to chain multiple promises? e.g.

(js-await [db (db "flow")
           v (get db id)
           ret (put db v)]
  (do-stuff ret)
  (catch err
         ...))

1
thheller12:06:29

I'm undecided on that front. I kinda like it simple, because people will for sure misuse this and treat it like a let thing which them breaks if something isn't actually returning a promise.

thheller12:06:53

promesa sort of does this and I personally do not like it

thheller12:06:21

(js-await [db (db "flow")]
  (js-await [v (get db id)]
    (js-await [ret (put db v)]
      (do-stuff ret))
    (catch err
           ...)))

potetm12:06:41

Yeah that ran through my head as well. I considered more complicated things and landed on "only do promises, manually do lets," for myself as well.

thheller12:06:42

also allows handling errors at separate stages

thheller12:06:27

and it still chains just fine

potetm12:06:31

Not certain, but I'm pretty sure a recursive js-await would allow the same level of err handling.

potetm12:06:51

output should be the same as doing the above^ only with fewer manual calls to js-await

thheller12:06:23

not quite, since I moved the error handling one lvl down. so it is not the same technically. but yeah otherwise it is

potetm12:06:14

oh I see what you're saying, yeah but there would be nothing stopping from using that^ way as well if that's what you want

thheller12:06:07

true. I oriented this more on the JS lvl, so that it stays close to JS semantics

potetm12:06:17

anyways, I'm not at all trying to convince you. I appreciate your general aesthetic. Hence why I asked first 😉

potetm12:06:25

I just did the work on my end, so I thought I'd ask

thheller12:06:57

yeah undecided for now. I do eventually want this to emit actual await, just didn't get to hacking this into the compiler yet

✔️ 1