Is this Swift Concurrency replacement for DispatchQueue.asyncAfter() functionally equivalent (and the best solution)? Seems to work correctly, but I haven't been able to find any good explanations for migrating from using DispatchQueue to Swift Concurrency.

Swift language source code showing use of DispatchQueue to wait 2.5 seconds:

            // original code
            DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
                withAnimation(.smooth) {
                    showHomeScreen = true    // this is a @State variable
                }
            }
Swift language source code showing use of Swift Concurrency to wait 2.5 seconds:

            // new code
            Task { @MainActor in
                try await Task.sleep(for: .seconds(2.5))
                withAnimation(.smooth) {
                    showHomeScreen = true	// this is a @State variable
                }
            }
0

If you have a fediverse account, you can quote this note from your own instance. Search https://ieji.de/users/puppethead/statuses/115894649983841005 on your instance and quote it. (Note that quoting is not supported in Mastodon.)