You’ve now built every piece of a laundry room program on its own. You’ve written a reminder that waits, a nag that repeats until it’s cleared, and a long job split into chunks. You’ve also read a file with an error-first callback and written machines that emit events. In this project, you’ll put those pieces together into one program for 14 Ferris Road.
This lesson is the brief. It says what the program has to do and splits the work into three steps, each one an exercise that checks your work, so you’ll come back to it while you build.
Read the Brief
Four housemates share the laundry room: Ines, Kofi, Wren, and Dev. There are three machines, washer 1, washer 2, and the dryer, and they finish at different times, with the dryer last. Nobody wants to stand in the basement waiting. Everybody wants to know when their own load is done, and nobody wants a wet load left in a machine for an hour.
Here’s what the program you’ll write has to do:
- Each machine announces its own news. A machine is an
EventEmitter, like theWasherclass you wrote. It emits"done"with the housemate’s name and the machine when a cycle ends, and"error"with anErrorobject when a load can’t start because the door is open. When a housemate empties it, it emits"collected". - A notifier tells the right housemate. It listens to all three machines. When a load is done, it messages the housemate whose load it is. When a machine reports an error, it alerts that housemate instead.
- A nag keeps at it. If a housemate hasn’t collected their laundry after a minute, the notifier nags them every minute until they collect it. Then the nag stops, and nothing is left scheduled for that load.
- Each machine keeps a cycle log. The program reads a machine’s log with an error-first callback, and it copes with a log that isn’t there.
In the story, the nag waits a minute, which would make a program slow to test. In a program you run at home, you’d scale that down to 20 seconds, and the exercises scale it down again, to milliseconds, so every test run finishes in about a second. Each exercise gives you its exact times and the exact lines its tests look for.
Here’s what one run of the finished notifier might log, with the approximate time in seconds at the start of each line. Timers don’t promise exact times, so your own run may differ by a few milliseconds. In this run, the nag comes every 200 milliseconds. Wren left washer 2’s door open, so Kofi’s load can’t start:
0.0s Laundry room alert for Kofi: washer 2's door is open
0.3s Ines, collect your laundry from washer 1
0.5s Ines, your laundry is still in washer 1 (nag 1)
0.7s Ines, your laundry is still in washer 1 (nag 2)
0.8s Ines emptied washer 1
1.0s Dev, collect your laundry from the dryer
1.2s Dev, your laundry is still in the dryer (nag 1)
1.3s Dev emptied the dryer