Created
December 16, 2022 06:21
-
-
Save boraseoksoon/613e6067a3881d52cd7f7a875c263679 to your computer and use it in GitHub Desktop.
cooperative thread pool test code
This file contains hidden or 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
import Foundation | |
// reference: https://stackoverflow.com/questions/67978028/maximum-number-of-threads-with-async-await-task-groups | |
func run() async { | |
await withTaskGroup(of: Void.self) { group in | |
for i in 0 ..< 32 { | |
group.addTask { | |
print(await fire(i)) | |
} | |
} | |
} | |
} | |
func run2() { | |
DispatchQueue.global().async { | |
DispatchQueue.concurrentPerform(iterations: 32) { i in | |
print(fire2(i)) | |
} | |
} | |
} | |
func fire(_ i: Int) async -> Int { i } | |
func fire2(_ i: Int) -> Int { i } | |
Task { | |
await run() | |
} | |
run2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment