- Chapter 1. Asynchronous JavaScript
- 1.1. Async XHR (3 second load time)
- 1.2. Example callback
- 1.3. Passing a callback as a predefined function
- 1.4. A callback being invoked asynchronously
- 1.5. Using synchronous code to write and read a file in Node.js
- 1.6. Using asynchronous code to write and read a file in Node.js
- 1.7. Naive asynchronous code
- 1.8. The jQuery.ready function can be synchronous or asynchronous
- 1.9. HTTP request in Node.js
- 1.10. Using setTimeout to demonstrate the event loop
- 1.11. Async XHR (3 second load time repeated from earlier)
- 1.12. Race condition
- Chapter 2. Introducing Promises
- 2.1. Using callbacks
- 2.2. Promise then and catch
- 2.3. Chaining calls using then and catch
- 2.4. Creating and resolving a promise
- 2.5. One promise with multiple consumers
- 2.6. The state of a promise never changes after it is fulfilled or rejected
- 2.7. Convenience functions for resolve and reject
- 2.8. Calls to then always return a new promise
- 2.9. Using then to sequence multiple steps
- 2.10. Passing values in a sequence of steps
- 2.11. Execution order of callbacks used by promises
- 2.12. Using a rejection handler at the end of a chain
- 2.13. Rejecting a promise by throwing an error in the constructor callback
- Chapter 3. Working with Standard Promises
- 3.1. The async ripple effect
- 3.2. Conditional async step
- 3.3. Substituting a resolved promise
- 3.4. Encapsulating conditional logic with a promise
- 3.5. Caching a promise
- 3.6. Running asynchronous tasks in parallel
- 3.7. Consolidating the outcomes of parallel tasks with Promise.all()
- 3.8. Running code after multiple operations have finished, regardless of their
- 3.9. Running tasks in parallel using a loop
- 3.10. Overview of array.reduce()
- 3.11. Simple array.reduce() to sum numbers
- 3.12. Build a sequential chain using a loop
- 3.13. Build sequential chain using recursion
- 3.14. Conditionally expanding a chain based on the outcome of a preceding promise
- 3.15. Manage response time using Promise.race()
- 3.16. Verbose pipeline
- 3.17. Concise pipeline
- Chapter 4. Using Libraries and Frameworks
- 4.1. Wrapping a thenable for interoperability
- 4.2. Wrap a native promise with a Bluebird promise
- 4.3. Using the enclosing scope through function.bind() or aliasing
- 4.4. Setting callback contexts using promise.bind()
- 4.5. Hiding the bound context from calling code
- 4.6. Node-style callback
- 4.7. Using promisify to wrap a node-style function
- 4.8. Converting arrays into individual arguments using promise.spread()
- 4.9. Specifying the execution context for a wrapped function
- 4.10. Using a promise-enabled filter and reduce
- 4.11. Eager invocation of aggregate functions
- 4.12. Exposing a fulfillment value using the enclosing scope
- 4.13. Passing on a value using promise.return()
- 4.14. Passing on a value using promise.tap()
- 4.15. Supplementing a chain with promise.tap()
- 4.16. Passing in multiple values with Promise.all()
- 4.17. Simple deferred object in jQuery
- 4.18. Deferred throws synchronous errors
- 4.19. Managing web worker results with deferred objects
- 4.20. Creating a deferred object using a standard Promise constructor
- Chapter 5. Error Handling
- 5.1. Explicitly rejecting a promise
- 5.2. Unhandled error rejects a promise
- 5.3. Functions that return promises should not throw errors
- 5.4. Promise chains built across functions
- 5.5. Logging and rethrowing an error
- 5.6. Bluebird reporting an unhandled rejection
- 5.7. A try/catch block
- 5.8. A traditional try/catch/finally block
- 5.9. Use catch/then to mimic catch/finally
- 5.10. Bluebird's promise.finally()
- 5.11. Sample call stack
- 5.12. Promise callback breaks up the call stack
- Chapter 6. Combining ECMAScript 6 Features with Promises
- 6.1. Array destructuring
- 6.2. Object destructuring
- 6.3. Object destructuring with function parameters
- 6.4. Array destructuring with function parameters
- 6.5. Destructuring the fulfillment value from Promise.all()
- 6.6. Using array.map() with an inline callback
- 6.7. Using array.map() with an arrow function
- 6.8. Concise pipeline (repeated from earlier chapter)
- 6.9. Concise pipeline with arrow functions
- 6.10. Using the iterable interface of an array
- 6.11. Managing asynchronous image loading using a promise
- 6.12. Hypothetical use of loadImage as a synchronous function
- 6.13. Using a promise with code that looks synchronous
- 6.14. Computing a series of values without using a generator
- 6.15. Computing a series of values using a generator
- 6.16. Passing values into the generator
- 6.17. Configuring an iterator with an initial parameter
- 6.18. The parameter in the first call to iterator.next() is always ignored
- 6.19. Finite iterations
- 6.20. Looping through iterations
- 6.21. Using an implicit iterator created by for…of
- 6.22. Throwing errors with the iterator
- 6.23. Using a promise with code that looks synchronous (repeated from earlier)
- 6.24. Sample async wrapper
- 6.25. Replacing try/catch with promise.catch()
- 6.26. Using async and await as proposed in ES7