Come Back Later: Review Challenges

The Course
•
3 min read

After several days

Without reopening the solutions, explain Promise.all versus allSettled; write a decoder rejecting null and malformed records; and trace a then callback relative to a synchronous log. Rebuild one update that preserves its input. These short recall tasks reveal different gaps than recognizing code you just read.

After a few weeks

Build a small quote-preview controller. Only the latest preview may publish, a rejected current request displays an error, and disposal prevents later output. Use a controlled request dependency, not a live API. Test old success, old failure, cancellation, and disposal explicitly. Then connect a form and verify keyboard use.

Use this review as a 20-minute starting session. It is extra practice after the seven-day plan. If a task exposes a missing idea, revisit that lesson and try a new value or schedule after closing the explanation. The suggested intervals are convenient starting points, not a measured optimal spacing schedule.

The course has covered a path from validated data to a maintainable asynchronous app. Further study can explore modules at package scale, asynchronous iterators, workers, performance, and type systems. Do not treat advanced syntax as a substitute for the contracts and tests you can already apply.

Predict and trace

Write the output before running. Follow the values through each call; if your prediction differs, identify the first step that surprised you.

Predict, then run JavaScript
async function main() {
  const order = [];
  const later = Promise.resolve().then(() => {
    order.push("later");
  });

  order.push("now");
  await later;
  console.log(order.join(", "));
}

main();
Check your prediction
now, later

A promise reaction does not interrupt the current synchronous push.

Build it yourself

Exercise

Come Back Later: Review Challenges: practise

Write createPublisher(publish), returning send(text) and dispose(). After disposal no send may call publish, even after repeated disposal. Print only Before from your recorded messages.

Your working space JavaScript
// Rebuild a lifecycle guard from memory.
Hint 1: the idea

One closure flag can protect every publication entry point.

Hint 2: a first step

dispose should set a stable value, not toggle it.

Show one solution
function createPublisher(publish) {
  let disposed = false;

  return {
    send(text) {
      if (!disposed) {
        publish(text);
      }
    },
    dispose() {
      disposed = true;
    }
  };
}

const messages = [];
const publisher = createPublisher(text => messages.push(text));

publisher.send("Before");
publisher.dispose();
publisher.dispose();
publisher.send("After");
console.log(messages.join(", "));
Before

Connect this guard to a deferred async result and resolve it after disposal. Then reject it instead, ensuring the rejection is handled without publishing.

Test a changed requirement

Connect this guard to a deferred async result and resolve it after disposal. Then reject it instead, ensuring the rejection is handled without publishing.

Explain before moving on

Which concepts did you retrieve independently? Name one new schedule you will test in your next project.

Was this article helpful?

Your response is saved on this device.