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 slowWork() async throws { for i in 1...5 { try await Task.sleep(nanoseconds: 300_000_000) // 0.3s try Task.checkCancellation() print("Step ", i) } } let sem = DispatchSemaphore(value: 0) let t = Task { do { try await slowWork() } catch { print("Cancelled") } sem.signal() } DispatchQueue.global().asyncAfter(deadline: .now() + 0.7) { t.cancel() } sem.wait()