Modern Concurrency: Getting Started, Episode 13: Displaying a Progress View | Kodeco


This is a companion discussion topic for the original entry at https://www.kodeco.com/28434449-modern-concurrency-getting-started/lessons/13

Hello :raised_back_of_hand:

I have one question related to the last part of the episode where you set self.isDownloadActive = false

Since this is inside a Task closure, which therefore is running in an asynchronous context, why it is not necessary in this case to manually call MainActor.run to perform the change in the variable? (since this property is annotated with @State and will refresh the view).

Regards,

Hi Jorge! I don’t remember whether I say this in the course, but in the book β€” Chapter 2 section 2.11 β€” Marin writes:

when your code creates a Task from the main thread, that task will run on the main thread, too. Therefore, you know you can update the app’s UI safely.