Javascript APIs with async properties

Getter properties are a great way to mask logic and expose what appears as static values. I find it extremely elegant to differentiate functionality from attributes. This logic may hide lazy calculations to be performed only on-demand, or it may hide logic that’s based on object’s, or even application state.

For example, a User object may have functionality like user.goOnline(), it should have attributes like user.isOnline. The check if a user is online should be performed on demand because this status may change from moment of instantiation to the moment of querying.

With the emerging of async/await in Javascript, it is now possible to create such lazy getters by pointing them to promises, creating more semantic APIs.

Static object can also leverage this way of typing. An API object pointing to async properties may also appear more readable.

When importing between modules — I feel the appeal is even greater.

And this just opens up endless sugary syntactic possibilities.

The following is a (simplified) real life example where I found using async getters made the final logic cleaner.
`git tag -a ${tag} -m "${await message}"`

omrilotan.com