Kitchen service

From the fantastic video: https://developer.apple.com/videos/play/wwdc2023/10170/?time=298, would you have a downloadable link to that kitchen service project?

I'm trying to understand how the method:

func handleShift<Orders>(orders: Orders) async throws

is called?

Because the video shows it to be called this way:

for cook in staff.keys {
    group.addTask { try await cook.handleShift() }
}

without arguments ...

Many thanks!

It happens some times that changes occurred in code between various video sequences (@6:10 and @12:10).

Did you try

  • to call as described here ? Do you get compiler error ? If no, that means there is another handleShift func, without parameters.
  • to pass an orders parameter ito call cook.handleShift() ? What happens then ?

I do not have an issue with multiple orders, but, with multiple cooks, handling different orders concurrently.

The orders are not in an array, but are coming from an AsyncSequence, 1 every second (mimicking a very busy soup restaurant!).

That AsyncSequence is the parameter for func handleShift<Orders>(orders: Orders) async throws, which I took outside the Cook object, and placed it inside the Kitchen service.

Inside it, looping through each available cook, I set the order, with a group task.

So, depending on how I write this, either my cooks are working on the same order (it should be 1 order for 1 cook) concurrently, or, my group task are not concurrent; meaning, the logic waits for the cook to complete its order before moving on to the next order, which will be assigned to the same cook, or, that AsyncSequence will not wait for the orders to be completed, ending too soon, so the code can no longer react on the non-assigned orders.

I just need to rethink this a bit, as it is obvious I messed up the creation of these various tasks :) This structured concurrency concept, group task, AsyncSequence, AsyncIterator are totally new to me, just trying to get my head around it, by messing up code :) :)

I will eventually solve this, but thanks for your help.

Kitchen service
 
 
Q