Hammerspoon: Asynchronous menu bar icon update

Created on 20 Feb 2020  路  2Comments  路  Source: Hammerspoon/hammerspoon

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.

Most helpful comment

Have you looked at hs.http.html.asyncGet?

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhenwenc picture zhenwenc  路  4Comments

aaronjensen picture aaronjensen  路  3Comments

piskov picture piskov  路  4Comments

jiahut picture jiahut  路  3Comments

dasmurphy picture dasmurphy  路  4Comments