Skip to content

Additional sugar: Timer.recordInterval(since: DispatchTime, now: DispatchTime = .now()) #79

@ktoso

Description

@ktoso

Noticed during our work on apple/swift-cluster-membership#70 and other projects this pattern:

extension Timer {
    /// Records time interval between the passed in `since` dispatch time and `now`.
    func recordInterval(since: DispatchTime, now: DispatchTime = .now()) {
        self.recordNanoseconds(now.uptimeNanoseconds - since.uptimeNanoseconds)
    }
}

emerges a lot when a message contains "sent at" or something like that, and then reporting metrics becomes timer.recordInterval(since: message.sentAt) leaving the user without any having to dance around math with the time amounts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions