Come Back Later: Review Challenges

The Course
•
3 min read

Return after several days without copying old solutions. Rebuild a lazy batch generator, a bounded counter and the first-failure recorder. State when generator validation executes and why a private field does not preserve an invariant without checks.

Next, recreate a two-gate ordering regression. Resolve the second job first and prove input-order output. Explain the difference between Promise.all preserving order and Promise.all limiting starts: it does the former, not the latter.

Finally, review the task-pool API from memory. Which callbacks receive a signal? When does rejection happen relative to active work? What happens if a callback never settles? Why does bounded concurrency still permit O(n) result memory? Identify one case that needs a source iterator cleanup test and one that needs a controlled schedule.

Predict, run, and explain

Write the output and trace the important state changes before checking it. Then run the program. Each editor is independent. Async examples end with main() so this editor waits for their work.

Predict, then run JavaScript
const original = { nested: { count: 1 } };
const copy = { ...original };

copy.nested.count = 2;
console.log(original.nested.count);
Check your prediction
2

Your turn

Exercise

Come Back Later: Review Challenges: practise

Write firstFailure() returning record and read. read returns {failed, value}. Record undefined and then “late”; print true and true for failed and value===undefined. No truthiness test may decide whether a failure exists.

Your workspace JavaScript
// Keep failure presence independent of its stored value.
Hint 1: the idea

Undefined can be a real thrown value.

Hint 2: a first step

Initialize a separate boolean and change it only on the first observation.

Show one solution
function firstFailure() {
  let failed = false;
  let value;

  return {
    record(error) {
      if (!failed) {
        failed = true;
        value = error;
      }
    },
    read() {
      return { failed, value };
    }
  };
}

const state = firstFailure();

state.record(undefined);
state.record("late");
console.log(state.read().failed);
console.log(state.read().value === undefined);
true
true

Explain why the implementation meets the stated contract. Which part is enforced by the language or checker, and which part needs behavioral evidence?

Change it and test it

Redo the retry brief after a week using controlled failures instead of timers. Explain the callback assumptions before coding. If you want types to enforce more caller relationships, continue with TypeScript beginner and intermediate; no framework is required for either path.

Was this article helpful?

Your response is saved on this device.