× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Kevin,

Amen! The hardest thing for me to wrap my head around was the asynchronous nature of AJAX calls. Sure, you can make them synchronous, but my recommendation is to bite the bullet and get a clear understanding of it first, work with callbacks without entering "hell" and then look at promises. Just trying to follow nested async calls would make my head hurt. Just about everything in node.js and JavaScript libraries in general is asynchronous so yeah, "hell hath no fury like asynchronous calls ..."

Generators in ES6 looks promising (no pun intended) so it looks like the future is getting a bit more manageable when it comes to async processes. Here is an article (among many) about ES6 generators: http://chrisbuttery.com/articles/synchronous-asynchronous-javascript-with-es6-generators/

I love this stuff. It just gets better and better....

Pete Helgren
www.petesworkshop.com
GIAC Secure Software Programmer-Java

On 10/23/2015 8:55 AM, Kevin Turner wrote:
Hello

Callback hell has been mentioned a few times (mainly by Nathan) and it is something that has been bugging me recently because I have indeed fallen into this trap. It is also known as the "pyramid of doom" because your code can end up looking like an ever increasingly complicated list of nested function calls.

However, mainly because Sails uses it "out of the box", I have educated myself in the use of "Promises". Promises allow you to write your asynchronous code in a synchronous way, such that callback hell can be eliminated.

I won't go into the details here, but if you are interested, look uphttps://github.com/kriskowal/q

Waterline ORM also uses a promises library called "bluebird":http://bluebirdjs.com/docs/getting-started.html

I have refactored a lot of horrific code now that I have a grip on this technique.....promises are beautiful thing!

Kevin


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.