Skip to content

Commit

Permalink
Simplify ClockFake implementation in the UseFakeClockType snippet.
Browse files Browse the repository at this point in the history
  • Loading branch information
fumoboy007 committed Jan 8, 2024
1 parent 7c571c6 commit c878857
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions Snippets/Advanced Use Cases/UseFakeClockType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ final class MyServiceImplementationTests: XCTestCase {
class ClockFake: Clock, @unchecked Sendable {
typealias Instant = ContinuousClock.Instant

private let realClock = ContinuousClock()

private let lock = NSLock()

private var _now: Instant

init() {
let realClock = ContinuousClock()
self._now = realClock.now
self.minimumResolution = realClock.minimumResolution
}

private var _now: Instant
var now: Instant {
lock.lock()
defer {
Expand All @@ -53,9 +52,7 @@ class ClockFake: Clock, @unchecked Sendable {
return _now
}

var minimumResolution: Duration {
return realClock.minimumResolution
}
let minimumResolution: Duration

func sleep(until deadline: Instant,
tolerance: Duration?) async throws {
Expand Down

0 comments on commit c878857

Please sign in to comment.