This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-13
Channels
- # ai (5)
- # announcements (4)
- # babashka (34)
- # beginners (78)
- # biff (6)
- # calva (41)
- # cider (47)
- # clerk (1)
- # clj-commons (3)
- # clj-http (1)
- # clojure (72)
- # clojure-europe (51)
- # clojure-nl (1)
- # clojure-norway (87)
- # clojure-romania (1)
- # clojure-uk (5)
- # clojuredesign-podcast (2)
- # community-development (1)
- # conjure (2)
- # cursive (11)
- # datomic (6)
- # docker (4)
- # emacs (13)
- # exercism (20)
- # hyperfiddle (56)
- # matrix (6)
- # membrane (4)
- # nbb (11)
- # off-topic (88)
- # pathom (7)
- # pedestal (1)
- # polylith (20)
- # portal (16)
- # practicalli (1)
- # re-frame (13)
- # reagent (4)
- # reitit (2)
- # remote-jobs (7)
- # shadow-cljs (49)
- # sql (4)
Docs say that nbb.core/slurp
returns a Promise. What is the correct way to await for the resolved value? (print (await (slurp "file.txt")))
is still returning a promise #object[Promise [object Promise]]
. Seems l am missing something
await
in nbb only works on top level values. in the REPL you can do
(await (slurp "file.txt"))
or
(def x (await (slurp "file.txt"))
also works, which binds the contents of the file to x
but you might as well use (require '["fs" :as fs])
and (fs/readFileSync "file.txt" "UTF-8")

Trying to make this function more readable, could someone suggest a better alternative to nested lets/ifs. Something like an early escape/return pattern? https://github.com/sher/nbb/blob/extend-fastify/examples/fastify/src/fastify_nbb/plugins/auth.cljs#L28-L41
(defn pre-handler
[req _ done]
(if (pathname-whitelisted? (j/get req :url))
:default
(let [cookies (j/get req :cookies)]
(if-let [signed-cookie (j/get cookies :token)]
(let [unsigned-cookie (.unsignCookie req signed-cookie)]
(if (j/get unsigned-cookie :valid)
(if-let [token (jwt-verify-sync (j/get unsigned-cookie :value))]
(println "--->>>" token)
(throw (js/Error "ERR_UNAUTHORIZED")))
(throw (js/Error "ERR_UNAUTHORIZED"))))
(throw (js/Error "ERR_UNAUTHORIZED")))))
(done))