liveBook · Manning

Temporal dependency

As explained in Functional Programming in JavaScript

A dependency in which one computation must wait for another to complete at a particular time before it can safely proceed.

A temporal dependency exists when one computation must wait for another to finish before the next action can safely run. Asynchronous requests create this problem because the request returns before its data arrives. Calling the next function immediately can therefore use null or incomplete data. section 8.1

Fetching students before displaying them

A student request must finish before showStudents runs. Passing showStudents as the success callback makes that ordering explicit; placing the call after getJSON without waiting does not.

Callbacks enforce the dependency, but several dependent requests can form a nested callback pyramid. Temporal coupling also appears when asynchronous calls are mixed with synchronous loops: a callback may capture the wrong student unless the current object is passed into its closure. section 8.1

Promises represent the waiting explicitly and provide a flatter way to compose dependent operations.

  • Wrap a future value or long-running operation in a pending promise. section 8.2
  • Consolidate failures with catch instead of repeating error callbacks. section 8.2

How Functional Programming in JavaScript covers it

How deep it goes
Works through callbacks, nested requests, closures, promises, chaining, and concurrency, but defers formal implementation theory.
Examples
Uses student records, grade requests, XMLHttpRequest, callback nesting, Promise chains, and Promise.all.
What it assumes
Assumes basic JavaScript functions and requests while teaching asynchronous timing, callbacks, closures, and promises through examples.
What you can do after
Apply it via JavaScript callbacks and promises to sequence dependent requests, handle errors, and parallelize independent work.
How it connects
Connects asynchronous programming with callbacks, closures, continuation-passing style, promises, error handling, and concurrency.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.