-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored
Task.sleep
nanosecond clamping math to new `Task.sleep(s…
…econds:)` method
- Loading branch information
Showing
6 changed files
with
37 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Concurrency Extensions.swift | ||
// OSCKit | ||
// | ||
// Created by Steffan Andrews on 2024-10-28. | ||
// | ||
|
||
import Foundation | ||
|
||
fileprivate let maxSeconds = TimeInterval(UInt64.max / 1_000_000_000) | ||
|
||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
extension Task where Success == Never, Failure == Never { | ||
/// Suspends the current task for at least the given duration in seconds. | ||
package static func sleep(seconds: TimeInterval) async throws { | ||
// safety check: protect again overflow | ||
|
||
let secondsClamped = min(seconds, maxSeconds) | ||
let nanoseconds = UInt64(secondsClamped * 1_000_000_000) | ||
|
||
try await sleep(nanoseconds: nanoseconds) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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