Don't need to set isDownloadActive to @MainActor?

Hello

I’m on ch2 challenges in Modern Concurrency in Swift.
I thought that I need to set isDownloadActive to @MainActor, because when it changes, UI is updating.
But the solution code doesn’t use @MainActor or something.

Do I miss something?

Thanks in advance.

I see your point, theoretically the second use of isDownloadActive should not be guaranteed to be running on the main actor here:

downloadSingleAction: {
  // Download a file in a single go.
  isDownloadActive = true
  Task {
    do {
      fileData = try await model.download(file: file)
    } catch { }
    isDownloadActive = false
  }
}

Interestingly, even with the strictest compiler checking enabled I don’t get a warning and I can’t repro a case where this code won’t run on the main thread.

I’ll look again into this but maybe I’m missing one of the many rules for executing task partials. Thanks for pointing me to this issue

2 Likes