JavaScript Promises: Applications in ES6 and AngularJS
3.9 (56 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
670 students enrolled
Wishlisted Wishlist

Please confirm that you want to add JavaScript Promises: Applications in ES6 and AngularJS to your Wishlist.

Add to Wishlist

JavaScript Promises: Applications in ES6 and AngularJS

Take your first steps into the world of JavaScript Promises to effortlessly code in an asynchronous environment
3.9 (56 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
670 students enrolled
Created by Packt Publishing
Last updated 2/2016
Curiosity Sale
Current price: $10 Original price: $75 Discount: 87% off
30-Day Money-Back Guarantee
  • 2.5 hours on-demand video
  • 1 Supplemental Resource
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • Create your own Promises to handle asynchronous processes
  • Decide the fate of a process: either as a success or a failed task
  • Add callbacks to determine what should be done upon completion
  • Chain promises into a full asynchronous flow
  • Change failures into successes to meet the needs of your specific application
  • Modify data to make it ready for display
  • Fight race conditions: wait for several parallel tasks to complete before moving on
  • Combine a varying number of asynchronous tasks in a sequential order
  • Simulate asynchronous behavior
  • Race Promises against each other and single out the fastest one
  • Choose between events and Promises
View Curriculum
  • Familiarity with JavaScript callbacks and function binding would be a bonus but is not a must.

Promises are the new rage! Within a year, they will be an indispensable tool for JavaScript developers, both frontend and backend. New navigator APIs such as battery status, geolocation, indexedDB, as well as libraries and frameworks such as Angular, Ionic, and more have already adopted Promises as the best way to handle asynchronous flow programming. From the most simple async tasks to parallel, series, and other convoluted flows, Promises will make your code clean, easy to understand, and actually fun to write.

Promises—if you’ve ever coded an AJAX call, chances are you used them. But did you know they can be used to avoid race conditions, or that you can combine them into complex flows, and ultimately that they can make coding in asynchronous environments a breeze? Learning JavaScript Promises: Practical Applications in ES6 and AngularJS will help you learn all this and more. All the features are backed with a real-life examples, from a local weather forecast to a movie search on iTunes!

Starting from the basics of resolving and rejecting Promises, we will gradually move on to controlling flows by redirecting outcomes, making failures into successes, and vice versa, and modifying data to make it ready for display. Once you have familiarized yourself with Promises, we will review the many awesome ways of combining Promises, such as waiting for all tasks or grabbing the first task to complete. Finally, we will ensure that you fully master Promises with a section on extra Promises that will provide further useful information and examples. Throughout the course, you will apply every single feature you have discovered by creating meaningful widgets that utilize Promises, both in ES6 and in AngularJS.

This course will not only make you feel comfortable utilizing Promises when they are provided, but will also make you appreciate how much easier they can make your programming in the future. You will gain hands-on, real-life knowledge and experience of a great technology that is on the rise.

About The Author

Mathieu Chauvinc is a Managing Director at Red Ape Solutions and works on keeping the company at the bleeding edge of web technologies. On a daily basis, he leads the tech team of 15 and collaborates with them in building complex single page applications and neat hybrid mobile apps. He has been involved in web technologies for over a decade, from Django to Go, SQL to NoSQL, Mootools to Angular, continuously trying to keep the right balance between the excitement of new frameworks and the stability of proven ones. He always has a special place in his heart for Python and Django.

He holds a Master’s in Engineering from the German University Karlsruhe and a Master’s in Engineering from the French ENSAM (Paris). Despite having an engineering background, he has always had a passion for knowledge sharing, which follows him to this day, and he regularly conducts corporate or free training on various I.T. topics in his adoptive country of Malaysia. He is also the author of the Introducing AngularJS, Packt Publishing video course.

Who is the target audience?
  • This course is for developers who have a basic understanding of JavaScript and of AngularJS. Knowledge of the difference between Controllers and Services will be of use.
Students Who Viewed This Course Also Viewed
Curriculum For This Course
20 Lectures
Introducing Promises
3 Lectures 15:43

This video will offer an overview of the course.

The Course Overview

Many processes in JavaScript are asynchronous and, thus, can be confusing for developers whose experience is mostly synchronous. Promise objects allow for a clear way to handle such processes.

Promises – You've Been Using Them All Along

Some services ($http) return promise objects when called, but other processes do not. Often, a developer will need to create their own asynchronous process, such as waiting for some user interactions or the completion of a navigator action. The $q service provides the tool to handle such cases.

Make Me a Promise
Resolving and Rejecting ES6 Promises
6 Lectures 53:41

Promises have become so popular that the new iteration of JavaScript ES6 implements them. This implementation is slightly different than the Angular $q service. We will learn how to create promises using the ES6 promises API.

Preview 09:11

Promises allow us to code parts of an asynchronous flow. Flows rarely follow a single direction; there are cases where things go awry. Promises prepare for these instances by having two possible outcomes: success and failure.

There Are Only Two Types of Promises in This World

Asynchronous process flows that are handled by promises are all about clarity of code and outcomes. Here, we will learn about the various ways to set callbacks for each case:

Deciding What’s Next

Some processes and flows require repeated information to be passed at unexpected times. Other flows, though of an unknown duration, expect their outcome to be final. Promises do not allow for second chances and, thus, are great tools to cover the latter of these cases.

No Second Chance

A lot of processes will need to conduct more than one task upon completion of an action. Although promises are strongly single-chance and single-value, when it comes to the callbacks, developers can add as many as they want, even after the promise has been settled, and, thus, allow for several actions to be added from various parts of an application.

Callbacks Execution and Timing

Angular 2 is coming and has everyone guessing with its breaking changes and new features. We will review where promises stand in that major overhaul.

The Future Is Coming – Angular v2 Promises
One Man's Garbage Is Another Man’s Gold
4 Lectures 37:29

JavaScript applications are becoming more powerful and complex, and so are corresponding asynchronous flows. One major trouble is to accomplish several processes leading to the next, even though the time taken for completion is unknown and the main thread doesn’t wait for these processes. Promises help controlling such flows by using chaining, which not only allows to run processes one after the other but also to alter the value that comes out of the fulfillment of this, or even the success or failure path taken by the promise.

Preview 12:04

Promises that represent one action resolve with a certain value. This value may be suitable for one flow, but not for another. Returning a normal value allows you to modify the resolve value of a promise to make it more relevant to an outlying context. In practice, this is really useful when grabbing API content to be displayed to a user.

Making API Data User-ready

When abstracting processes in general and not only asynchronous ones, we make an assumption as to what successes and what failures are. However, depending on a situation, what appears to be a success for one block, could actually represent a failure for the whole flow. Promises make it very easy to switch from a success to a failure in the next promise, and we will learn how to accomplish this. We will also give practical examples as to why this would be a useful feature.

Changing Successes into Failure

In the same vein as the previous video, this will cover cases where a certain block of a process needs to be transformed from a failure into a success. Promises allow us to do this by returning anything but a rejected promise.

Turning Failure into Success
Combining Promises
3 Lectures 19:46

More than one action is needed and wherever possible, it is better to complete these actions in parallel without having to wait for the other to complete. We will use two API calls and display data in a simple case where the calls are independent of each other.

Preview 04:16

Sometimes, several tasks need to be completed before a process can move on. A solution to this issue is to complete them one after the other. However, wherever possible, it is always more efficient to run tasks in parallel. $q.all allows you to combine promises in a way that must all complete before the surrounded process continues.

Interdependent Tasks

In some cases, we do not know how many times a particular asynchronous task is expected to be run before stopping it. Using promises, we will be able to handle "n" tasks in a series.

Series Flow - with a Twist
Extra Promises
4 Lectures 30:56

When a function needs to return a promise, for example, a service that's returning to a controller, but the return value is not guaranteed to be a promise, $q.when can be used to ensure that the return is indeed a promise.

Preview 08:41

As we will show in an example, not returning any value within a .catch can lead to unexpected behavior. We will see how to handle this correctly.

The Pitfall of No Return

Most older JavaScript libraries deal exclusively in events when handling asynchronous processes. Here, we will compare the pros and cons of each.

Promises Versus Events

Given a list of tasks, we need to know as soon as a single one of them is complete Promise.all allowed us to wait for all. Promise.race will allow us to trigger as soon as any of the tasks are complete.

Race to the Finish Line
About the Instructor
Packt Publishing
3.9 Average rating
7,336 Reviews
52,355 Students
616 Courses
Tech Knowledge in Motion

Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.

With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.

From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.

Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.