Chapter 4. Mastering Promises

This chapter will cover the following recipes:

  • Understanding and implementing basic Promises
  • Chaining Promises and Promise handlers
  • Creating Promise wrappers with Promise.resolve() and Promise.reject()
  • Implementing Promise barriers with Promise.all()
  • Canceling asynchronous actions with Promise.race()
  • Converting a Promise into an Observable
  • Converting an HTTP service Observable into ZoneAwarePromise

Introduction

In Angular 1, promises acted as strange birds. They were essential for building robust asynchronous applications, but using them seemed to come at a price. Their implementation by way of the $q service and the duality of promise and deferred objects seemed bizarre. Nonetheless, once you were able to master them, it ...

Get Angular 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.