If you are using shadow-cljs there is also
But you picked an example that doesn’t need either the async
keyword nor the await
.
This is functionally equivalent to the async/await JS variant you posted.
(defn login []
(.loginWithRedirect auth0client
(clj->js
{:authorizationParams
{:redirect_uri js/window.location.origin}})))
Or if you really must use async and maybe want to do something with the result, you can do so with js-await
from shadow-cljs.
(defn login []
(js-await [result
(.loginWithRedirect auth0client
(clj->js
{:authorizationParams
{:redirect_uri js/window.location.origin}}))]
result
(catch failure
(prn [:login-failed failure])
::fail!)))
;; or regular old .then interop
(defn login []
(-> (.loginWithRedirect auth0client
(clj->js
{:authorizationParams
{:redirect_uri js/window.location.origin}}))
(.then (fn [result]
result))
(.catch (fn [failure]
(prn [:login-failed failure])
failure))))
An async
function in JS is nothing but a regular function that returns a Promise
. If all you do is call a function that returns a promise then you can just return that and you are done. You can of course to .then
interop if you want. I strongly recommend NOT using core.async for Promise interop, if that is your only use of core.async. It is fine if you are already using core.async elsewhere.