@mattiem High-level advice question for you, if you have some time (if not, that's okay, just posing the question helps me think it through): I'm working on an app that uploads assets. You drop one or more images (or videos, or whatever) on it, it generates zero or more derived assets (think smaller versions), and uploads the original and derived files to a server.
All of this work should take place in the background. I would like for each operation to contribute to progress feedback to the user, both for each individual asset, and all operations as a whole. Each asset and the whole set should be cancelable.
How would you structure the concurrency for this? A top-level Task
for each asset that kicks off a TaskGroup for the generation and upload of each derived asset? An Actor that holds processing state for each derived asset? I find myself falling into Dispatch ways of thinking.
One of the challenges is that I’m using SwiftData, which can create multiple instances of an entity, making it harder for an entity to hold onto a reference to the tasks related to it (does that make sense?). All I can think of is some kind of keyed collection of “progress" objects, maybe keyed off the entity ID.
=> More informations about this toot | More toots from JetForMe@geekstodon.com
@JetForMe Good question! The uploads will all be off the main thread. So the only thing you need to worry about, i think is any processing you need to do. You may be able to keep this super simple with some MainActor state to represent the uploads in progress and the tasks (part of a task group I guess..) that writes to their little bit of that state as they progress.
=> More informations about this toot | More toots from mattiem@mastodon.social
@mattiem Would that progress state be actor objects designated as MainActor? Or just a @MainActor class? SwiftUI definitely needs to get at it, but background tasks need to update it (and trigger SwiftUI updates).
=> More informations about this toot | More toots from JetForMe@geekstodon.com
@JetForMe Classes marked MainActor should work. Definitely a good place to start. As you make progress if you run into issues let me know! It’s hard to give good advice for abstract stuff…
=> More informations about this toot | More toots from mattiem@mastodon.social This content has been proxied by September (3851b).Proxy Information
text/gemini