boatcoder
boatcoder

Reputation: 18107

How to know a promise has been fulfilled so I can chain to it or use its result?

When a user selects an employee, I make an async request to the server for the employee's events. If the user then proceeds to assign a task to the employee they selected before the server can respond with the event list for the employee, I need to defer that assignment until the event list arrives. The event list is loaded via $http.get() so I have a promise to work from. But what if that promise has already been satisfied? The event list might look like an empty array, so I can't rely on looking at the array to know if it has been satisfied.

If I add a .then to an already satisfied promise, does it get called immediately?

Upvotes: 1

Views: 89

Answers (1)

Gabe
Gabe

Reputation: 2137

The function that you've passed to then will execute immediately if the promise has been resolved.

Upvotes: 2

Related Questions