liveBook · Manning

Chapter 17: Coordinating timelines

What you will learn in chapter 17 of Grokking Simplicity

Introduces the need to coordinate timelines even when they do not share an explicit resource.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces the need to coordinate timelines even when they do not share an explicit resource.

Key terms: timelines, coordinate, possible orderings

17.1 Principles of working with timelines

This section summarizes ways to make timelines easier to reason about and introduces treating time as something code can manipulate directly.

Key terms: timelines, possible orderings, shared resources, coordinate, first-class concept, reusable objects, implicit model of time, ordering of calls, repetition of calls

17.2 There’s a bug!

The section introduces an intermittent wrong-total bug in the shopping cart after UI speed optimizations.

Key terms: shopping cart queue, wrong total

17.3 How the code was changed

The section explains how a small code change made two AJAX requests run at the same time, improving speed but introducing a bug.

Key terms: shipping_ajax(), cost_ajax() callback, ajax requests

17.4 Identify actions: Step 1

The section explains why a local variable must be included when identifying actions for a new timeline diagram if multiple timelines access it.

Key terms: timeline diagram, total, multiple timelines, simplify

17.5 Draw each action: Step 2

This section completes the action-by-action timeline diagram, placing the final callback on the timeline where it runs before simplifying the diagram.

Key terms: timeline diagram, actions, shipping_ajax(), update_total_dom(), simplify

17.6 Simplify the diagram: Step 3

The section simplifies a JavaScript timeline diagram and identifies a variable shared across the remaining timelines.

Key terms: consolidate actions, consolidate timelines, JavaScript threading model, shared resource, total variable, local variable

17.7 Possible ordering analysis

The section identifies a callback ordering that causes a bug despite the requests being initiated in the intended order.

Key terms: total, shipping_ajax() callback, cost_ajax() callback, timelines

17.8 Why this timeline is faster

The section uses timeline diagrams to explain why parallel AJAX requests can reduce wait time while their responses can still arrive in an unpredictable order.

Key terms: timeline, parallel, sequence, DOM, cost_ajax, shipping_ajax, response payload

17.9 Waiting for both parallel callbacks

The section explains how a cut lets two parallel AJAX callbacks finish before their shared total is written to the DOM.

Key terms: ajax responses, callbacks, total local variable, DOM, cut, timelines, possible orderings

17.10 A concurrency primitive for cutting timelines

This section explains how a completion-counting primitive can coordinate timelines that finish in different orders, and why JavaScript can implement it with a simple variable.

Key terms: primitive, timelines, callback, race condition, single thread, mutable variable, atomic update

17.11 Using Cut() in our code

The section shows where to put Cut() in the add-to-cart code, what callback to give it, and why done() must be called at the end of each timeline.

Key terms: Cut(), done(), calc_cart_total(), update_total_dom(), timeline, concurrency primitive, Promise.all()

17.12 Uncertain ordering analysis

The section divides the add-to-cart timeline into regions to check which action orderings need analysis before claiming the parallel version behaves correctly.

Key terms: timeline, dotted lines, possible ordering

17.13 Parallel execution analysis

The section checks that coordinating two parallel AJAX responses preserves the speed benefit while keeping the required ordering for one click.

Key terms: parallel execution, cut the timeline, cost_ajax(), shipping_ajax()

17.14 Multiple-click analysis

Analyzes how a queue and Cut() handle multiple shopping-cart clicks, then considers which sources of concurrency complexity are worth changing.

Key terms: queue, Cut(), ajax requests, timeline diagram, possible orderings, asynchronous web requests, API responses, uncertainty of the user’s interactions

17.15 A primitive to call something just once

The section introduces JustOnce(), a reusable concurrency primitive that lets multiple timelines share an action while allowing it to have an effect only once.

Key terms: JustOnce(), concurrency primitive, higher-order function, idempotent, mutable variable, timeline, atomic update

17.16 Implicit versus explicit model of time

The section contrasts JavaScript’s implicit rules for ordering and repetition with concurrency primitives that make those rules explicit.

Key terms: implicit model of time, ordering, repetition, timelines, explicit model of time, Queue(), Cut(), JustOnce(), DroppingQueue(), first-class actions

17.17 Summary: Manipulating timelines

The section summarizes five ways to improve multiple timelines, ordered from most to least preferred.

Key terms: timelines, actions, calculations, implicit inputs and outputs, shared resources, queues, locks, concurrency primitives, promises, cuts

17.18 Conclusion

The chapter concludes that coordinating timelines makes the result reliable even when web requests return in an unpredictable order.

Key terms: race condition, coordination between timelines, primitive

17.19 Summary

17.20 Up next…

This section closes the discussion of first-class functions and timelines and previews a discussion of design focused on onion architecture.

Where this is used later

Concepts explained in this chapter

← Chapter 16: Sharing resources between timelines Chapter 18: Reactive and onion architectures →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.