paint-brush
Don't Nest Callbacks, Use Promise Chaining Insteadby@hungvu
2,160 reads
2,160 reads

Don't Nest Callbacks, Use Promise Chaining Instead

by Hung Vu6mMay 26th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

JavaScript promise chaining is a simple but powerful feature to resolve a common nested callback issue (callback hell). To chain promises, there are two main points you need to remember. Multiple then and catch can be called successively such as promise.then(...).then(...).catch(...).catch(...). A call back in the then method must return a new Promise object so the chain can be continued. The rule also applies to TypeScript. In ES2016 (a.k.a ES7), the async/await function was introduced and it makes our life even easier. That said, if you cannot use the ES7 feature for some reason, then promise chaining is a great choice to refactor your codebase.

Coin Mentioned

Mention Thumbnail
featured image - Don't Nest Callbacks, Use Promise Chaining Instead
Hung Vu HackerNoon profile picture
Hung Vu

Hung Vu

@hungvu

A technology enthusiast, more of a generalist you can say. Love to document my learning journey!

About @hungvu
LEARN MORE ABOUT @HUNGVU'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Hung Vu HackerNoon profile picture
Hung Vu@hungvu
A technology enthusiast, more of a generalist you can say. Love to document my learning journey!

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Also published here
Newsbreak
Platypush
Coffee-web
Learnrepo
Writingcontests
Asorrybowl
Grimneko
Dcs0