Skip to content

Instantly share code, notes, and snippets.

@SebastianBoldt
Last active February 4, 2022 13:36
Show Gist options
  • Save SebastianBoldt/93fba63eb7a4a78a83aee65b8c8c344d to your computer and use it in GitHub Desktop.
Save SebastianBoldt/93fba63eb7a4a78a83aee65b8c8c344d to your computer and use it in GitHub Desktop.
actor BankAccount {
private var balance: Int = 0
let accountHolder: String? // 3.
init(accountHolder: String) {
self.accountHolder = accountHolder // 2.
}
func logBalance() {
print(balance) // Accessing Balance without await
}
}
let bankAccount = BankAccount(accountHolder: "Sebastian Boldt")
Task {
await bankAccount.logBalance() // 1.
print(bankAccount.accountHolder ?? "No account associated") // 3.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment