You are previewing You Don't Know JS: Async & Performance.
O'Reilly logo
You Don't Know JS: Async & Performance

Book Description

The "You Don't Know JS" series takes a closer look at the features of JavaScript that developers find confusing, and therefore avoid, or use incorrectly. As part of this series, this guide focuses on the new asynchronous features in JavaScript, which are confusing to developers. You'll learn about promises, generators, and coroutines, all of which allow you to create more sophisticated single-page web applications that provide the features of a desktop application without tying up the user's browser.

Table of Contents

  1. Foreword
  2. Preface
    1. Mission
    2. Review
    3. Conventions Used in This Book
    4. Using Code Examples
    5. Safari® Books Online
    6. How to Contact Us
  3. 1. Asynchrony: Now & Later
    1. A Program in Chunks
      1. Async Console
    2. Event Loop
    3. Parallel Threading
      1. Run-to-Completion
    4. Concurrency
      1. Noninteracting
      2. Interaction
      3. Cooperation
    5. Jobs
    6. Statement Ordering
    7. Review
  4. 2. Callbacks
    1. Continuations
    2. Sequential Brain
      1. Doing Versus Planning
      2. Nested/Chained Callbacks
    3. Trust Issues
      1. Tale of Five Callbacks
      2. Not Just Others’ Code
    4. Trying to Save Callbacks
    5. Review
  5. 3. Promises
    1. What Is a Promise?
      1. Future Value
      2. Completion Event
    2. Thenable Duck Typing
    3. Promise Trust
      1. Calling Too Early
      2. Calling Too Late
      3. Never Calling the Callback
      4. Calling Too Few or Too Many Times
      5. Failing to Pass Along Any Parameters/Environment
      6. Swallowing Any Errors/Exceptions
      7. Trustable Promise?
      8. Trust Built
    4. Chain Flow
      1. Terminology: Resolve, Fulfill, and Reject
    5. Error Handling
      1. Pit of Despair
      2. Uncaught Handling
      3. Pit of Success
    6. Promise Patterns
      1. Promise.all([ .. ])
      2. Promise.race([ .. ])
      3. Variations on all([ .. ]) and race([ .. ])
      4. Concurrent Iterations
    7. Promise API Recap
      1. new Promise(..) Constructor
      2. Promise.resolve(..) and Promise.reject(..)
      3. then(..) and catch(..)
      4. Promise.all([ .. ]) and Promise.race([ .. ])
    8. Promise Limitations
      1. Sequence Error Handling
      2. Single Value
      3. Single Resolution
      4. Inertia
      5. Promise Uncancelable
      6. Promise Performance
    9. Review
  6. 4. Generators
    1. Breaking Run-to-Completion
      1. Input and Output
      2. Multiple Iterators
    2. Generator-ing Values
      1. Producers and Iterators
      2. Iterables
      3. Generator Iterator
    3. Iterating Generators Asynchronously
      1. Synchronous Error Handling
    4. Generators + Promises
      1. Promise-Aware Generator Runner
      2. Promise Concurrency in Generators
    5. Generator Delegation
      1. Why Delegation?
      2. Delegating Messages
      3. Delegating Asynchrony
      4. Delegating Recursion
    6. Generator Concurrency
    7. Thunks
      1. s/promise/thunk/
    8. Pre-ES6 Generators
      1. Manual Transformation
      2. Automatic Transpilation
    9. Review
  7. 5. Program Performance
    1. Web Workers
      1. Worker Environment
      2. Data Transfer
      3. Shared Workers
      4. Polyfilling Web Workers
    2. SIMD
    3. asm.js
      1. How to Optimize with asm.js
      2. asm.js Modules
    4. Review
  8. 6. Benchmarking & Tuning
    1. Benchmarking
      1. Repetition
      2. Benchmark.js
    2. Context Is King
      1. Engine Optimizations
    3. jsPerf.com
      1. Sanity Check
    4. Writing Good Tests
    5. Microperformance
      1. Not All Engines Are Alike
      2. Big Picture
    6. Tail Call Optimization (TCO)
    7. Review
  9. A. asynquence Library
    1. Sequences and Abstraction Design
    2. asynquence API
      1. Steps
      2. Errors
      3. Parallel Steps
      4. Forking Sequences
      5. Combining Sequences
    3. Value and Error Sequences
    4. Promises and Callbacks
    5. Iterable Sequences
    6. Running Generators
      1. Wrapped Generators
    7. Review
  10. B. Advanced Async Patterns
    1. Iterable Sequences
      1. Extending Iterable Sequences
    2. Event Reactive
      1. ES7 Observables
      2. Reactive Sequences
    3. Generator Coroutine
      1. State Machines
    4. Communicating Sequential Processes (CSP)
      1. Message Passing
      2. asynquence CSP emulation
    5. Review
  11. C. Acknowledgments