26 May '15, 3pm

Taming the Async w/ #Angularjs Promises #javascript

Taming the Async w/ #Angularjs Promises #javascript

Async (aka asynchronous) JavaScript refers to the execution of more than one piece of code at the same time. This is great because it prevents your application from freezing up when certain code takes a long time to execute, but it can also cause issues in your code if you are expecting something to be complete when it may not be. These situations are called race conditions . Here is an example of when a function is performing asyc code and we don’t get the result we are expecting: http://codepen.io/dganoff/pen/oXLNeb . Notice the name variable isn’t returned as “Bob”, but is instead returned as it’s initial value. Enter: Promises Promises allow developers to detect when asynchronous code finishes and then act on it. Instead of a function returning a value we expect, we can have it return a Promise, and then let the Promise tell us when the value is ready to use. Now let’s...

Full article: http://www.intridea.com/blog/2015/5/26/angular-promises-t...

Tweets