DEV Community

Cover image for Callback Hell and How to Rescue it ?
Nikhil Upadhyay
Nikhil Upadhyay

Posted on • Updated on

Callback Hell and How to Rescue it ?

Liquid syntax error: Unknown tag 'endraw'

Top comments (10)

Collapse
 
mukuljainx profile image
Mukul Jain

Nice article, check this out npmjs.com/package/await-handler
Using this we can skip the try catch block and handle error there it self. Like in case you want to show different error message for different errors, one way to go.

    let [err, result] = await on(myAsyncTask());
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jerrycode06 profile image
Nikhil Upadhyay

Nice, Thanks for sharing this!!

Collapse
 
aman-godara profile image
Aman Godara

Thanks, enjoyed reading it!

Collapse
 
sidhunishan786 profile image
Nishan Singh

Nicely written!!

Collapse
 
andreidascalu profile image
Andrei Dascalu

"I think you should know about Synchronous and Asynchronous programming in JavaScript(or any other language)"

Except that no ... the three patterns of Async programming you describe don't apply to any other language except Javascript.
While ReactPHP has some things that resemble callbacks, just about any other async-capable language uses multithreading, either soft threads (managed by the platform such as Go's goroutines or PHP Swoole's coroutines), system threads or full-blown parallelism.

For a fully relevant discussion on async programming, it might be better to start with concurrency vs parallelism and then see what JS is capable of.

Collapse
 
jerrycode06 profile image
Nikhil Upadhyay

This article basically focuses on callback hell and I have given just a quick overview of async programming, although I agree on your point -
"the three patterns of Async programming you describe don't apply to any other language except Javascript."
Thank you for mentioning it, I should've added it to my article.

Collapse
 
farazkhanfk7 profile image
Hasan Faraz Khan

Great piece :-)

Collapse
 
jerrycode06 profile image
Nikhil Upadhyay

Thanks ;-)

Collapse
 
oddward profile image
Mugtaba G

Awesome piece~ Thanks for the detailed yet clear and practical post

Collapse
 
jerrycode06 profile image
Nikhil Upadhyay

Glad you liked it.