liveBook · Manning

Chapter 16: Sharing resources between timelines

What you will learn in chapter 16 of Grokking Simplicity

The introduction explains why timelines sometimes need to share resources safely, while previewing the chapter’s approach.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why timelines sometimes need to share resources safely, while previewing the chapter’s approach.

Key terms: timelines, resources, share resources

16.1 Principles of working with timelines

This section explains why simpler timelines are easier to analyze and why timelines must coordinate when they share resources.

Key terms: timelines, steps, shared resources, possible orderings, coordinate, take turns

16.2 The shopping cart still has a bug

The section shows why two shopping-cart timelines that update the shared DOM can produce different results depending on their order.

Key terms: timelines, shared DOM resource, DOM updates, possible orderings

16.3 We need to guarantee the order of the DOM updates

Explains why asynchronous DOM updates may arrive out of click order and how a queue can preserve that order.

Key terms: timelines, DOM updates, network request, queue, shared resource, timeline, shared resources, global variables, DOM, shared local variables

16.4 Building a queue in JavaScript

The section builds a JavaScript queue that processes cart updates in click order across asynchronous timelines, then contains the queue’s mutable state.

Key terms: click handler, cost_ajax(), calc_cart_total(), queue, queue_items, shift(), working, runNext(), callback, Queue()

16.5 Principle: Use real-world sharing as inspiration

The section explains why sharing resources must be programmed explicitly and suggests using familiar real-world sharing arrangements as inspiration.

Key terms: share resources, queue, queues, locks, book pools, blackboards

16.6 Making the queue reusable

This section turns the shopping-cart queue into a reusable way to run tasks in order and call back when each task finishes.

Key terms: done(), worker(), Queue(), runNext(), replace body with callback, callback, item.data, higher-order function, concurrency primitive, linearize()

16.7 Analyzing the timeline

The section uses a timeline diagram to check whether the shopping cart, DOM, and queue remain correct when multiple clicks create overlapping timelines.

Key terms: shared resources, cart global variable, dotted line, DOM updates, queue, single timeline, dotted lines, queue concurrency primitive

16.8 Principle: Analyze the timeline diagram to know if there will be problems

This section explains why drawing and analyzing timeline diagrams helps reveal timing problems that tests may miss.

Key terms: timeline diagrams, shared resources, possible orderings, timing bugs

16.9 Making the queue skip

This section explains how a dropping queue avoids processing obsolete pending updates while preserving the task already in progress.

Key terms: dropping queue, update_total_queue, unprocessed item

16.10 Conclusion

The chapter concludes that an ordering problem in shared DOM updates was solved with a reusable queue.

Key terms: resource-sharing issue, DOM, queue, higher-order function

16.11 Summary

16.12 Up next…

Recaps the chapter’s work on resource-sharing issues and previews coordinating timelines in the next chapter.

Where this is used later

Concepts explained in this chapter

← Chapter 15: Isolating timelines Chapter 17: Coordinating timelines →

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.