I used core.async to background a slow task, namely fetching the HTML of the saved URL and parsing out the <title> tag.
I need to do a bit of yak-shaving. As I alluded to before, I want to use Server-sent Events, to send the above background update to the client on completion. To do that, I have to switch libraries. Up to now, I’ve used Compojure, but after reading up on SSE and Clojure, I have been convinced that I need to use either Pedestal or yada.
After doing a little bit of research, I feel that Pedestal will suit me better as it uses core.async to do all of its async things and hey, I’m using that, too! With that settled, I am now realizing that I need to port all of my currently written code to this new way of doing things. There doesn’t seem to be a magical “take this Compojure app and make it a Pedestal app” command in Leiningen, so I am left with a few options. I think what I’ll do is generate a Pedestal app, then copy over the generated bits into the current app and smush them together. I hope it works!
Go, go, go, lein generator!
OK, in a directory above the current app directory, I need to run the Leiningen generator.
This goes and does things and now I have a new directory. I now need to copy over bits from project.clj, the whole server.clj and service.clj, the config, log, and target directories. Then, in the new service.clj file, I need to copy over the code from handler.clj. All in all, this is how the project and service files look like.
With that, I start the REPL and run the server from it.
A proof in form of a GIF
That’s it for now. The stage is set up for SSE, which will be the next thing I tackle. Until then.
I deployed the app to Heroku, here. The code can be seen here.