-
-
Save alexito4/549a9c1e634269e1100cf57754e069ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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