JavaScript | Promises

 JavaScript promises are object which used for holding value of Async operation. The value can be either success and failure. 

You can refer below links to learn more about promises.

  1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
  2. https://javascript.info/promise-basics
In earlier post I'd mentioned about callbacks. Adding multiple callbacks in code make code more complicated and not readable. We can solve this issue with callbacks.

The $.get used already returns promise object so we can directly call then() method of promise object to do processing. We returned the call to second rest so that its result will be available in chain format.
This is useful where we have to call one rest one after another. The fail() at last of chain can be added to catch any errors.

See the Pen Promise by Rohan (@rohanlopes20) on CodePen.

Comments

Popular posts from this blog

Spring | Using TIBCO EMS with Spring framework

TIBCO | For Loop - Accumulate output

TIBCO | JNDI Server & JMS Instance creation