Promise Maker — JavaScript

Village promise maker: 22 levels predicting microtask order and building retry, cancel and circuit-breaker pipelines. Real instrumented Promises in a Worker.

What the levels ask

  1. Lightning struck the signal tower on the hill, so Mr. Tono opened a pigeon post. Order what his board records for pos.js, first to last: the seal on envelope p, the p.then tag taken off the line, and every printed line.
  2. Rara leaves three letters (A, B, C) and two promised replies. Order everything the board prints, first to last.
  3. Grandma Marni asks if her grandson is ready to come home, and the promise was kept on the very first line. Order what the board prints, first to last.
  4. Mrs. Ratna reads one letter to two classes: two .then wait on the same envelope p. Order what the board prints, first to last.
  5. Mr. Piksel lets the first pigeon go with a zero-millisecond setTimeout: it perches again at once. When does Mr. Tono take its note? Order what the board prints.
  6. Dina sends a design to her client through the function work, which waits with await. Order what the board prints, first to last.
  7. Mr. Harun's bus is cancelled: envelope p is broken from the very first line. Order the board's records: the seal on envelope p and every printed line.
  8. Bagas's letter falls on the way: the .then callback throws an error. Order the board's records: the first .then tag taken off the line, and every printed line.
  9. Mr. Dodi needs a spare part. Ask the district workshop for the part's number, then send that number to the town shop. The function orderPart gives back a promise holding [partNo, townReply], broken if either does not reply.
  10. Mrs. Yanti waits on three suppliers (p1, p2, p3) who keep their promises at different times. Promise.all waits for them all. Order what the board prints.
  11. The neighbourhood head invites three neighbouring villages to a meeting and wants news from ALL of them, recording those who do not reply too. The function inviteToMeeting sends three pigeons at once and is never broken.
  12. Mrs. Yanti needs mushrooms for her food stall and asks three gardens at once. The function findMushrooms takes the FIRST reply that brings a letter (pigeons that come back empty are skipped), the moment it comes. If they all come back empty, the promise is broken.

And more, 22 levels in all.