Beyond the basics of structured concurrency

RSS for tag

Discuss the WWDC23 Session Beyond the basics of structured concurrency

Posts under wwdc2023-10170 tag

2 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Using discardingTaskGroup to limit concurrent tasks?
I'm having trouble understanding the use case for discardingTaskGroup. In my app, I want to submit 10 concurrent image upload requests; usually, I'd just fire off 10 unstructured Task {} instances (I'm assuming this is fine) for image in images { Task { do { try await uploadImage(item: item, image: image) } catch { // Handle any errors } } } But then I thought I'd actually like to have a max of ~3 uploads concurrently, where I would prioritize the images that appear to the user earlier first. I know using group.next() in a taskGroup we can await on previous results and add tasks as required. But my task does not return data, rather it performs an action. So, it seems like the new discardingTaskGroup could be a useful API. Task { do { try await withThrowingDiscardingTaskGroup { group in for image in images { group.addTask { try await uploadImage(item: item, image: image) } } } } catch { // Handle any errors } } How can I convert this discarding task group code to only include a max of n tasks running concurrently? And is this even a reasonable use of the new API to begin with? Best, T
1
0
1k
Aug ’23
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!
2
0
636
Jul ’23