Run ❯
Get your
own
website
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
import Dispatch func square(_ n: Int) async -> Int { n * n } print("Start") let sem = DispatchSemaphore(value: 0) Task { var results: [Int] = [] await withTaskGroup(of: Int.self) { group in for n in [1,2,3] { group.addTask { await square(n) } } for await val in group { results.append(val) } } print(results.sorted().map(String.init).joined(separator: ",")) sem.signal() } sem.wait() print("Done")