Skip to content

Commit 0124d9a

Browse files
authored
Change Timer.record(duration: Duration) signature to avoid source breakage (#144)
1 parent eb18581 commit 0124d9a

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

Sources/Metrics/Metrics.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ extension Timer {
8282
///
8383
/// - Parameters:
8484
/// - duration: The `Duration` to record.
85-
///
86-
/// - Throws: `TimerError.durationToIntOverflow` if conversion from `Duration` to `Int64` of Nanoseconds overflowed.
8785
@available(macOS 13, iOS 16, tvOS 15, watchOS 8, *)
8886
@inlinable
89-
public func record(_ duration: Duration) {
87+
public func record(duration: Duration) {
9088
// `Duration` doesn't have a nice way to convert it nanoseconds or seconds,
9189
// and manual conversion can overflow.
9290
let seconds = duration.components.seconds.multipliedReportingOverflow(by: 1_000_000_000)

Tests/MetricsTests/MetricsTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ class MetricsExtensionsTests: XCTestCase {
111111

112112
let duration = Duration(secondsComponent: 3, attosecondsComponent: 123_000_000_000_000_000)
113113
let nanoseconds = duration.components.seconds * 1_000_000_000 + duration.components.attoseconds / 1_000_000_000
114-
timer.record(duration)
114+
timer.record(duration: duration)
115115

116116
// Record a Duration that would overflow,
117117
// expect Int64.max to be recorded.
118-
timer.record(Duration(secondsComponent: 10_000_000_000, attosecondsComponent: 123))
118+
timer.record(duration: Duration(secondsComponent: 10_000_000_000, attosecondsComponent: 123))
119119

120120
let testTimer = try metrics.expectTimer(timer)
121121
XCTAssertEqual(testTimer.values.count, 2, "expected number of entries to match")

0 commit comments

Comments
 (0)