Skip to content

Instantly share code, notes, and snippets.

View vukcevich's full-sized avatar

Marijan Vukcevich vukcevich

  • Huntington Beach, California
View GitHub Profile
@icanzilb
icanzilb / Task.sleep.swift
Created September 9, 2021 09:30
Task.sleep(seconds:)
extension Task where Success == Never, Failure == Never {
/// Suspends the current task for at least the given duration in seconds.
/// Throws if the task is cancelled while suspended.
/// - Parameter seconds: The sleep duration in seconds.
static func sleep(seconds: TimeInterval) async throws {
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
}
}