Skip to content

Instantly share code, notes, and snippets.

@icanzilb
Created September 9, 2021 09:30
Show Gist options
  • Save icanzilb/04a67c729e5ca82d06ed72b1555ae472 to your computer and use it in GitHub Desktop.
Save icanzilb/04a67c729e5ca82d06ed72b1555ae472 to your computer and use it in GitHub Desktop.
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))
}
}
@Denis411
Copy link

Why not make the method throwing ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment