Created
February 3, 2022 16:18
-
-
Save SebastianBoldt/b54b3c6755f00bc9dbb963b494922c40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getUser() async throws -> User { | |
try await Task.sleep(nanoseconds: 1_000_000) | |
let task = Task(priority: .high) { () -> Address in | |
try await Task.sleep(nanoseconds: 1_000_000) | |
return Address(street: "FooStreet") | |
} | |
let address = try await task.value | |
return User(name: "Max", address: address) | |
} | |
Task(priority: .medium) { | |
let user = try await getUser() | |
print(user.name) | |
print(user.address ?? "No Street available") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment