Skip to content

Instantly share code, notes, and snippets.

@barron9
Last active Jul 1, 2021
Embed
What would you like to do?
let accounts = [BankAccount(accountNumber: 1,initialDeposit: 100),BankAccount(accountNumber: 2,initialDeposit: 100),]
let q0 = DispatchQueue(label: "queue0", attributes: .concurrent)
q0.async
{
do {
accounts.forEach {
account in
async {
try await account.transfer(amount: 1, to: accounts[1])
}
}
}
}
q0.async
{
do {
accounts.forEach {
account in
async{
try await account.transfer(amount: 2, to: accounts[1])
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment