I want to have a menu bar whose icon updates in response to events of another application. The application is Syncthing, which provides an HTTP API for event polling. You make an HTTP request which blocks until an event occurs, or it times out after, say, a minute. All is good and I can poll the API and update the menu bar icon, but the entire Hammerspoon hangs while waiting for an event to occur. Surely, the event polling should be done asynchronously.
I don't see how coroutines can help me here. And I recently discovered that truly asynchronous task execution is not a strong point of Lua. Does anyone have suggestions? I found issue #122 that discussed asynchronous tasks but sadly made little progress.
Have you looked at hs.http.html.asyncGet?
No, I hadn't, and it works like a charm! It even supports HTTPS requests, perfect :)
Thanks a lot @asmagill
Most helpful comment
Have you looked at hs.http.html.asyncGet?