Promises vs. Observables with AJAX
A question that always comes up when discussing using observables to make AJAX requests is: “Why not promises?” As we learned in Chapter 1, Creating Observables, a promise represents a single value delivered over time where an observable represents multiple values. An AJAX request is a single value—why complicate things?
Promises are simpler in concept, but the real world always complicates things. Pretend you’re developing the mobile platform for a ridesharing app. Users will typically use the app outside, away from solid Wi-Fi. They’re trying to get somewhere, so they have a low tolerance for latency and errors. With that in mind, we’ll use the following code to build the best user experience for updating ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access