Structure_Concurrency5.9.0
ContinuousClock
A clock that measures time that always increments but does not stop incrementing while the system is asleep.
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
struct ContinuousClock
ContinuousClock
can be considered as a stopwatch style time. The frame of reference of the Instant
may be bound to process launch, machine boot or some other locally defined reference point. This means that the instants are only comparable locally during the execution of a program.
This clock is suitable for high resolution measurements of execution.
Citizens in _Concurrency
Conformances
protocol Clock
A mechanism in which to measure time, and delay work until a given point in time.
protocol Sendable
A type whose values can safely be passed across concurrency domains by copying.
Members
init(
) static var now: ContinuousClock.Instant
The current continuous instant.
var minimumResolution: Duration
The minimum non-zero resolution between any two calls to
now
.var now: ContinuousClock.Instant
The current continuous instant.
func sleep(until: ContinuousClock.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.
struct Instant
A continuous point in time used for
ContinuousClock
.
Features
static var continuous: ContinuousClock
A clock that measures time that always increments but does not stop incrementing while the system is asleep.
func measure(() throws -> Void
) rethrows -> Self.Instant.Duration Measure the elapsed time to execute a closure.
func sleep(for: Self.Instant.Duration, tolerance: Self.Instant.Duration?
) async throws Suspends for the given duration.