Skip to content

Instantly share code, notes, and snippets.

@wisecsj
Created November 1, 2022 11:05
Show Gist options
  • Save wisecsj/f15afe12c3c7ff1849b4ed52ecb832ab to your computer and use it in GitHub Desktop.
Save wisecsj/f15afe12c3c7ff1849b4ed52ecb832ab to your computer and use it in GitHub Desktop.
class Settings {
var count:Int=0
}
actor Test{
// var count:Int=0
var settings:Settings
init(s:Settings){
self.settings = s
}
}
let test = Test(s:Settings())
await withTaskGroup(of: Void.self){group in
for i in 1...10000{
print("index:\(i)")
group.addTask{
await add()
}
}
}
func add() async {
await test.settings.count+=1
}
print(await test.settings.count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment