JavaScript with Promises: Managing Asynchronous Code

JavaScript with Promises: Managing Asynchronous Code

by Daniel Parker
JavaScript with Promises: Managing Asynchronous Code

JavaScript with Promises: Managing Asynchronous Code

by Daniel Parker

Paperback

$19.99 
  • SHIP THIS ITEM
    Qualifies for Free Shipping
  • PICK UP IN STORE
    Check Availability at Nearby Stores

Related collections and offers


Overview

Asynchronous JavaScript is everywhere, whether you're using Ajax, AngularJS, Node.js, or WebRTC. This practical guide shows intermediate to advanced JavaScript developers how Promises can help you manage asynchronous code effectively—including the inevitable flood of callbacks as your codebase grows. You'll learn the inner workings of Promises and ways to avoid difficulties and missteps when using them.

The ability to asynchronously fetch data and load scripts in the browser broadens the capabilities of JavaScript applications. But if you don't understand how the async part works, you'll wind up with unpredictable code that's difficult to maintain. This book is ideal whether you're new to Promises or want to expand your knowledge of this technology.

  • Understand how async JavaScript works by delving into callbacks, the event loop, and threading
  • Learn how Promises organize callbacks into discrete steps that are easier to read and maintain
  • Examine scenarios you'll encounter and techniques you can use when writing real-world applications
  • Use features in the Bluebird library and jQuery to work with Promises
  • Learn how the Promise API handles asynchronous errors
  • Explore ECMAScript 6 language features that simplify Promise-related code

Product Details

ISBN-13: 9781449373214
Publisher: O'Reilly Media, Incorporated
Publication date: 06/19/2015
Pages: 92
Product dimensions: 6.80(w) x 8.80(h) x 0.30(d)

About the Author

Daniel Parker is a software developer focused on web and mobile applications. He writes JavaScript for Evernote in Austin, Texas and is the organizer of the Austin Google Developer Group.

Table of Contents

Preface v

1 Asynchronous JavaScript 1

Callbacks 2

Asynchronous JavaScript 3

Run to Completion and the Event Loop 6

Summary 10

2 Introducing Promises 11

Basic Usage 11

Multiple Consumers 14

Promise States 15

Chaining Promises 18

Callback Execution Order 19

Basic Error Propagation 20

The Promise API 22

Summary 24

3 Working with Standard Promises 25

The Async Ripple Effect 25

Conditional Logic 26

Parallel Execution 28

Sequential Execution Using Loops or Recursion 30

Managing Latency 35

Functional Composition 36

Summary 37

4 Using Libraries and Frameworks 39

Promise Interoperability and Thenables 40

The Bluebird Promise Library 40

Loading Bluebird 41

Managing Execution Context 41

Wrapping Node.js Functions 43

Working with Collections of Promises 46

Manipulating Fulfillment Values 48

Promises in jQuery 50

Summary 54

5 Error Handling 55

Rejecting Promises 55

Passing Errors 57

Unhandled Rejections 58

Implementing try/catch/finally 59

Using the Call Stack 61

Summary 63

6 Combining ECMAScript 6 Features with Promises 65

Destructuring 65

Arrow Functions 67

Iterables and Iterators 68

Generators 69

Synchronous Style 69

Generators and Iterators 70

Sending Values to a Generator 72

Sending Errors to a Generator 76

Practical Application 77

Summary 79

Index 81

From the B&N Reads Blog

Customer Reviews