Tech talks: Async Javascript

Tech talks: Async Javascript

Especially when you are coming from Java word, the first encounter with asynchronous style used in Javascript (or node.js) can be confusing. And of course there are several ways how to deal with it.

  • Callback hellAs also for other styles, modularization and good names helps in readability.
  • Async libraryThis library helps with increasing intendations and covers almost any use case. It is very useful at least to be aware of their options.
  • Promises (ES6)It is different style then node.js (default) error first callbacks. Working with promises feels more natural (you get “async” result as result of function instead of passing callback argument, but YMMV). However for this reason this approach does not work directly with node.js API. You need to wrap the code or use other solutions like es6-promisify (which can have some limitations)

    Another problem is inconsistent error handling however in node.js and chrome it seems to work fine.

  • async/await (ES7)Still not standardized, you need babel or similar solution to make it working. Similar style to promises. We had some problems when we tried to use in in some high-order functions (but can’t remember anymore).

Till now there is no obvious winner and maybe future will show.

Add a comment

*Please complete all fields correctly

Related Blogs

Posted by Stanislav Miklik | March 29, 2018
Number One Conference application
Our latest addition to our portfolio is new family of conference applications Conf One. We used it to build applications for a few conferences already with great success. It allows...
Posted by Stanislav Miklik | September 8, 2017
Code formatters battle – who is nicer?
Why do I need one? Every programmer has its own coding style. It is polite to honour the style of the file I am editing but when I am starting...
No Image
Posted by Stanislav Miklik | February 24, 2017
Is React Native fully compatible between Android and IOS?
Recently we were invited to help others to resolve compatibility issues between IOS and Android. They have started with React Native but have developed their application only for Android. And...