Tech talks: Async Javascript

Tech talks: Async Javascript

Posted by Stanislav Miklik | December 4, 2015 | javascript, tech-talks

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 miklik | 08 September 2017
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…
Posted by miklik | 24 February 2017
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…
Posted by miklik | 19 December 2016
What do you want for christmas? We wanted a color picker for React Native but we could not find any. Therefore we made one for you. You can find it…