Abstract

JavaScript has become more and more popular in recent years because its wealthy features as being dynamic, interpreted and object-oriented with first-class functions. Furthermore, JavaScript is designed with event-driven and I/O non-blocking model that boosts the performance of overall application especially in the case of Node.js. To take advantage of these characteristics, many design patterns that implement asynchronous programming for JavaScript were proposed. However, choosing a right pattern and implementing a good asynchronous source code is a challenge and thus easily lead into less robust application and low quality source code. Extended from our previous works on exception handling code smells in JavaScript and exception handling code smells in JavaScript asynchronous programming with promise, this research aims at studying the impact of three JavaScript asynchronous programming patterns on quality of source code and application.

Highlights

  • The very first JavaScript asynchronous error handling pattern is the “error-first callback” pattern, which was introduced in Node.js

  • Error handling with promise now is easier, likely using try catch in synchronous programming because all the asynchronous operation are at the same source code level

  • Beside the two errors handling code smells we analyzed in [6]: “Error swallowing in onRejected handler” and “Missing error handling at the end of promise chain”, in this paper we study a new error handling code smell: “Missing global rejected promise to handle code smell”

Read more

Summary

The error-first callback pattern

The very first JavaScript asynchronous error handling pattern is the “error-first callback” pattern, which was introduced in Node.js. This is a standard for callback throughout Node.js. If the requested asynchronous operation was failed, it would provide an error object as the first argument of the callback. If the reading process failed, the callback function will be invoked with the err parameter is not null. This parameter contains the error of the file reading process. Err will be set to null and the data contains the content of the requested file

Callback advantages
The downsides of using callbacks
Asynchronous programming and error handling using promise
Missing global promise rejection to handle code smell
Asynchronous error handling with async function
Improved asynchronous programming and error handling experience
Conclusion
Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call