Skip to content

Instantly share code, notes, and snippets.

@alexito4
Created Dec 30, 2022
Embed
What would you like to do?
print("Let's span a bunch of tasks and see how many cooperative threads are created.")
await withTaskGroup(of: Void.self) { group in
for i in 1...100 {
group.addTask {
print("Enter \(i)")
for n in 1...100000 {
let a = i * n
print(a)
}
try? await Task.sleep(for: .seconds(2))
for n in 1...100000 {
let a = i * n
print(a)
}
print("Exit \(i)")
}
}
}
print("Done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment