Games Node.js Loop Quest

Loop Quest

The event loop: call stack, timers, promises, async/await, nextTick, setImmediate, events and errors.

0 / 44 levels · 0 / 132 ★Start playing ›
  1. World 1 One chef, one stove

    Node is a kitchen with exactly one chef. The call stack is what the chef is cooking right now, and the chef finishes it before touching anything else.

  2. World 2 Alarm clocks

    setTimeout is an alarm clock. It never interrupts the chef. When it rings, its callback waits in line until the stove is free.

  3. World 3 The express lane

    Promise callbacks are the express lane. Whenever the chef's hands are free, the express lane is emptied before any alarm clock gets a turn.

  4. World 4 The VIP line

    process.nextTick is the VIP line. It cuts in front of even the express lane, so use it sparingly.

  5. World 5 Round the loop

    The event loop walks a circle: timers, then I/O (deliveries), then check (setImmediate), and back again. Each stop has its own queue.

  6. World 6 Events and errors

    An EventEmitter is a doorbell wired straight to the kitchen: pressing it makes the chef answer right now. Errors only reach a catch that is still on the stack.

  7. World 7 Don't block the chef

    With one chef, a dish that takes ten minutes stops every other order. Long synchronous work, or an endless VIP line, freezes the whole server.

Your rulebook

Finish a level to add its rule. Fill the book and you can explain all of this in an interview.

  1. 1Finish Top to bottom to unlock this rule.
  2. 2Finish Functions stack up to unlock this rule.
  3. 3Finish Last in, first out to unlock this rule.
  4. 4Finish A throw unwinds the stack to unlock this rule.
  5. 5Finish 0ms still waits to unlock this rule.
  6. 6Finish Shortest alarm first to unlock this rule.
  7. 7Finish A timer inside a timer to unlock this rule.
  8. 8Finish Equal alarms to unlock this rule.
  9. 9Finish The clock starts now to unlock this rule.
  10. 10Finish An alarm that repeats to unlock this rule.
  11. 11Finish Promises beat timers to unlock this rule.
  12. 12Finish new Promise runs now to unlock this rule.
  13. 13Finish Chains take turns to unlock this rule.
  14. 14Finish await pauses one function to unlock this rule.
  15. 15Finish Errors skip to .catch to unlock this rule.
  16. 16Finish Promise.all keeps order to unlock this rule.
  17. 17Finish async always returns a promise to unlock this rule.
  18. 18Finish A throw becomes a rejection to unlock this rule.
  19. 19Finish finally passes it on to unlock this rule.
  20. 20Finish Awaiting a timer to unlock this rule.
  21. 21Finish Promise.race takes the first to unlock this rule.
  22. 22Finish allSettled waits for everyone to unlock this rule.
  23. 23Finish nextTick cuts in to unlock this rule.
  24. 24Finish A tick inside a promise to unlock this rule.
  25. 25Finish The full lineup to unlock this rule.
  26. 26Finish Ticks first, as a group to unlock this rule.
  27. 27Finish A tick inside a tick to unlock this rule.
  28. 28Finish Between two timers to unlock this rule.
  29. 29Finish Timeout or immediate? to unlock this rule.
  30. 30Finish Inside I/O, immediate wins to unlock this rule.
  31. 31Finish An immediate inside an immediate to unlock this rule.
  32. 32Finish Inside I/O: the full lineup to unlock this rule.
  33. 33Finish emit is synchronous to unlock this rule.
  34. 34Finish once fires once to unlock this rule.
  35. 35Finish try/catch misses the future to unlock this rule.
  36. 36Finish await makes try/catch work to unlock this rule.
  37. 37Finish Cutting in line to unlock this rule.
  38. 38Finish The 'error' event to unlock this rule.
  39. 39Finish emit doesn't wait to unlock this rule.
  40. 40Finish Nobody caught it to unlock this rule.
  41. 41Finish A busy stack delays timers to unlock this rule.
  42. 42Finish An endless VIP line to unlock this rule.
  43. 43Finish An endless express lane to unlock this rule.
  44. 44Finish Cut the work into chunks to unlock this rule.