JavaScript Promises: Applications in ES6 and AngularJS

Take your first steps into the world of JavaScript Promises to effortlessly code in an asynchronous environment
4.5 (41 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.
536 students enrolled Bestselling in JavaScript Promises
$19
$75
75% off
Take This Course
  • Lectures 20
  • Length 2.5 hours
  • Skill Level Beginner Level
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

About This Course

Published 11/2015 English

Course Description

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.

What are the requirements?

  • Familiarity with JavaScript callbacks and function binding would be a bonus but is not a must.

What am I going to get from this course?

  • 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

What 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.

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.

Curriculum

Section 1: Introducing Promises
02:17

This video will offer an overview of the course.

07:15

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.

06:11

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.

Section 2: Resolving and Rejecting ES6 Promises
09:11

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.

08:39

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.

10:55

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:

09:57

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.

10:45

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.

04:14

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.

Section 3: One Man's Garbage Is Another Man’s Gold
12:04

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.

09:13

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.

08:30

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.

07:42

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.

Section 4: Combining Promises
04:16

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.

08:05

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.

07:25

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.

Section 5: Extra Promises
08:41

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.

04:18

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.

09:25

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

08:32

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.

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Packt Publishing, Tech Knowledge in Motion

Over the past ten years Packt Publishing has developed an extensive catalogue of over 2000 books, e-books and video courses aimed at keeping IT professionals ahead of the technology curve. From new takes on established technologies through to the latest guides on emerging platforms, topics and trends – Packt's focus has always been on giving our customers the working knowledge they need to get the job done. Our Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.

Ready to start learning?
Take This Course