Swift Concurrency question (Swift 5, no approachable concurrency, nonisolated default actor isolation): when you add a simple Task block in a func in a view controller, I thought it always executes on the main thread if the callee invokes that func while on main. If you want to run code on a background thread, you implement an async func and call it in the Task, but the next line in the Task would still be back on main. Is that wrong, any line in the Task body can run on any thread??
@jordanhipwell you wanna throw that question into a gist?
@mattiem Something like this, I thought I knew this super basic thing years ago ๐Ÿ˜…
@jordanhipwell can you maybe annotate the code with a more specific part you are confused by. Iโ€™m still not 100% sure I understand the question.

@mattiem My expectation was the Task body would always start executing on the main thread, execute the async StoreKit function on a background thread, then execute the remaining code on main thus ensuring all UI updates (loadingView, alert) occur on main.

But I'm getting rare/random crashes modifying auto layout on a background thread (only in one app where I have this pattern in place, not my other app interestingly), making me question everything ๐Ÿ˜…

@jordanhipwell @mattiem unless the Task is annotated @MainActor it will be on the global executor.

So if you switch this to:

Task { @MainActor in

}

@murfin @jordanhipwell that is only true if the enclosing method is nonisolated, which I think is really whatโ€™s at issue here.