Change Timer.record(duration: Duration) signature to avoid source breakage (#144)

This commit is contained in:
hamzahrmalik 2024-05-15 06:36:25 +01:00 committed by GitHub
parent eb18581491
commit 0124d9ad5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 5 deletions

View File

@ -82,11 +82,9 @@ extension Timer {
///
/// - Parameters:
/// - duration: The `Duration` to record.
///
/// - Throws: `TimerError.durationToIntOverflow` if conversion from `Duration` to `Int64` of Nanoseconds overflowed.
@available(macOS 13, iOS 16, tvOS 15, watchOS 8, *)
@inlinable
public func record(_ duration: Duration) {
public func record(duration: Duration) {
// `Duration` doesn't have a nice way to convert it nanoseconds or seconds,
// and manual conversion can overflow.
let seconds = duration.components.seconds.multipliedReportingOverflow(by: 1_000_000_000)

View File

@ -111,11 +111,11 @@ class MetricsExtensionsTests: XCTestCase {
let duration = Duration(secondsComponent: 3, attosecondsComponent: 123_000_000_000_000_000)
let nanoseconds = duration.components.seconds * 1_000_000_000 + duration.components.attoseconds / 1_000_000_000
timer.record(duration)
timer.record(duration: duration)
// Record a Duration that would overflow,
// expect Int64.max to be recorded.
timer.record(Duration(secondsComponent: 10_000_000_000, attosecondsComponent: 123))
timer.record(duration: Duration(secondsComponent: 10_000_000_000, attosecondsComponent: 123))
let testTimer = try metrics.expectTimer(timer)
XCTAssertEqual(testTimer.values.count, 2, "expected number of entries to match")