That’s a confusing use of the term async, but I understand what you mean, except it seems all your calls to A and B are actually synchronous in this case, or at least that’s what I gather?
In any case, it doesn’t seem to be the issue is with async, but just managing state. For managing state, an atom is a good choice. In your case, you want to cache the auth-token, and atoms are great for that, you could also look into memoize
and company. Technically you can also leverage closures, deftype or recursion, but those are more advanced and honestly I wouldn’t say they are better, atom is what you want in my opinion.
Yes there is. You want to use clj-refactor Home · clojure-emacs/clj-refactor.el Wiki · GitHub
Once you have that, there’s a feature called Magic requires, it’ll automatically add the require for common alias, and if you’ve had the alias for it already in another namespace, it’ll pick that up as well, and you can add your owns to cljr-magic-require-namespaces
So basically if you type str/
the require for clojure.string aliased to str
will be added automatically and the ns declaration will get re-evaluated as well so you can start using it immediately at the REPL.
Finally, the one you probably want the most is add-missing-libspec see here: cljr add missing libspec · clojure-emacs/clj-refactor.el Wiki · GitHub
There’s other refactorings available in it as well that can be handy.
Emacs is a bit of a beast, but can be quite productive for Clojure once you figure it out. I recommend a combo of packages for Clojure:
clojure-mode + Cider + clj-refactor + smartparens + aggressive-indent-mode + adjust-parens + flycheck-clj-kondo
Clojure-mode does syntax highlighting, indentation, and some basic refactorings. Cider gives you integrated REPL, debugger, documentation, auto-complete, code navigation and code browsing, clj-refactor adds more refactorings and what I mentioned before, smartparens does bracket management and structural code edits, aggressive-indent-mode keeps everything auto-indented and formatted all the time, adjust parens lets you wrap/unwrap code using tab, and flycheck-clj-kondo gives you very powerful real-time linting.
Setting this all up is a bit tricky, but that’s part of learning Emacs. I also use Spacemacs and have other customizations that are not Clojure specific per-say but add a lot of features to Emacs like a project panel, smart jumps in the code, git integration, command auto-completion, etc.