Skip to content

Instantly share code, notes, and snippets.

@barron9
Last active July 1, 2021 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barron9/42e0dc3436e8f65c312ff207007565c6 to your computer and use it in GitHub Desktop.
Save barron9/42e0dc3436e8f65c312ff207007565c6 to your computer and use it in GitHub Desktop.
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