PROMISES PARADIGMA

Introducing an alternative solutions to the callback system

Promises are another way to manage asynchronous code, without relying on the callback mechanism.
Callbacks presents following disadvantages:

The jQuery snippet used here performs following actions: first a normal callback is invoked, just to recall the callback approach, reading data from the my_data.xml file. Then we read same data using the promises approach, managing also the failure scenario. The next test regards invoking two promises, to show that each promise is "kept" with respect of the position of the actual call (i.e. the $.get() call), without considering position of the then(), done() or fail() method.
Finally, we show an example of usage of the when operator, allowing to check when both promises have been kept.

For details have a look to HTML code of this page.

Sources

HOME