Nettuts+ Promises Tutorial

A new tutorial posted on Nettuts with the most clear explanation of the Promises Design Pattern that I have encountered so far.

Understanding Promises

Trevor Burnham on Feb 22nd 2012

A Promise is an object that represents a one-time event, typically the outcome of an async task like an AJAX call. At first, a Promise is in a pending state. Eventually, it’s either resolved meaning the task is done or rejected if the task failed. Once a Promise is resolved or rejected, it’ll remain in that state forever, and its callbacks will never fire again.

You can attach callbacks to the Promise, which will fire when the Promise is resolved or rejected. And you can add more callbacks whenever you want – even after the Promise has been resolved/rejected! In that case, they’ll fire immediately.

Plus, you can combine Promises logically into new Promises. That makes it trivially easy to write code that says, “When all of these things have happened, do this other thing.”

see the whole article at Wrangle Async Tasks with jQuery Promises | Nettuts+.

Leave a Reply

Your email address will not be published. Required fields are marked *