Skip to content

Commit d443911

Browse files
authored
Update LESSONPLAN.md
1 parent 8d1f6d0 commit d443911

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Week2/LESSONPLAN.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,33 @@ fetchResource(`https://api.openweathermap.org/data/2.5/weather?q=amsterdam&appid
111111
```
112112

113113
### Excercise
114+
> Async can be hard to understand without real live example. Cooking is a great example of mixed synchronous and asynchronous tasks. In this assignment we'll cook pasta with promises 💍
115+
116+
Let's say we want a programme to cook some pasta. Some of the steps involved in cooking pasta are:
117+
118+
1. Gathering the ingredients (pasta, garlic, tomatoes, sage, butter)
119+
2. Cutting the garlic
120+
3. Cutting the tomatoes
121+
4. Cooking the water
122+
5. Cooking the pasta
123+
6. Baking the garlic
124+
7. Baking the tomatoes
125+
X. Mixing the pasta with sauce
126+
127+
If we do this synchronolously there is no chance of it becoming a good meal because the pasta would be cold by the time the vegetables are ready. It would also take way too long this way. So let's fix that!
128+
129+
1. Think about how to do this asynchronously; which tasks could be run at the same time? What steps should wait for what other steps? Try to write down a basic recipe (don't write any code yet!)
130+
2. Now convert your recipe to pseudocode (in markdown). The point is to name functions and show which functions call which other functions. The logic should be there but we'll write the code in the next step.
131+
3. Write the actual code using promises. Add timeouts to each task (estimate how many minutes a task would take and then set the timeout to that many seconds so 8 minutes for cooking pasta would be 8 seconds in your programme)
132+
4. Can you get the code to work like you would cook pasta in the kitchen? Try using Promise.all if you want to wait for several tasks to finish.
133+
134+
<!--- Here is my own attempt at completing the exercise. It's actually pretty tough to get the whole thing working with promises so maybe see how far students can get. https://codepen.io/Razpudding/pen/Keygge --->
135+
136+
> Async await really helps simplify asynchronous (promisified) code. The previous example can be improved by applying it.
137+
138+
5. Try rewriting your previous attempt using Async/Await. ⏰🍝⏰
139+
140+
<!--- Here is my solution. It's a lot cleaner than the promises version but could still use some work. Would also be nice if the changes were reflected in the DOM. https://codepen.io/Razpudding/pen/RJZeJO --->
114141

115142
### Essence
116143

0 commit comments

Comments
 (0)