Complexity measures how difficult a software situation is to understand or analyze. With multiple clicks, queued actions and parallel AJAX callbacks can create several possible execution orderings. section 17.14
Timeline diagrams make the sources of complexity visible:
- Parallel requests require multiple responses before the shopping-cart total can update the DOM. section 17.14
- A queue handles rapid clicks, while Cut() separates the timeline into shorter portions that are easier to analyze. section 17.14
- The remaining parallel area has two timelines and two possible orderings; later work proceeds sequentially. section 17.14
Two register requests
Calling countRegister twice starts two asynchronous requests that update a shared sum when their callbacks return. Their completion order becomes part of the behavior that must be checked. section 17.14
var sum = 0;
function countRegister(registerid) {
var temp = sum;
registerTotalAjax(registerid, function(money) {
sum = temp + money;
});
}
countRegister(1);
countRegister(2);
Inspect the JavaScript listing that launches two register-counting calls and exposes the shared-result interaction. section 17.14












