Structureswift 6.0.1_Concurrency
SuspendingClock
A clock that measures time that always increments but stops incrementing while the system is asleep.
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
struct SuspendingClock
SuspendingClock
can be considered as a system awake time clock. The frame of reference of the Instant
may be bound machine boot or some other locally defined reference point. This means that the instants are only comparable on the same machine in the same booted session.
This clock is suitable for high resolution measurements of execution.
Citizens in _Concurrency
Conformances
protocol Clock<Duration>
A mechanism in which to measure time, and delay work until a given point in time.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Escapable
protocol Sendable
Types
Type members
init(
) static var now: SuspendingClock.Instant
The current instant accounting for machine suspension.
Instance members
var minimumResolution: Duration
The minimum non-zero resolution between any two calls to
now
.var now: SuspendingClock.Instant
The current instant accounting for machine suspension.
func sleep(until: SuspendingClock.Instant, tolerance: Duration?
) async throws Suspend task execution until a given deadline within a tolerance. If no tolerance is specified then the system may adjust the deadline to coalesce CPU wake-ups to more efficiently process the wake-ups in a more power efficient manner.
Type features
static var suspending: SuspendingClock
A clock that measures time that always increments but stops incrementing while the system is asleep.
Instance features
func measure(() throws -> Void
) rethrows -> Self.Instant.Duration Measure the elapsed time to execute a closure.
func measure(isolation: isolated (any Actor)?, () async throws -> Void
) async rethrows -> Self.Instant.Duration Measure the elapsed time to execute an asynchronous closure.
func sleep(for: Self.Instant.Duration, tolerance: Self.Instant.Duration?
) async throws Suspends for the given duration.