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
