Skip to content

Commit

Permalink
Merge pull request #828 from carsten-wenderdel/advance-by-timeinterval
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiAAPeres committed Jul 23, 2021
2 parents d861efd + 4dfa99f commit 3c448a4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# master
*Please add new entries at the top.*

1. `TestScheduler` can `advance` by `TimeInterval`. (#828)

1. Fixed spelling error in `Token` class documentation.

# 6.6.1
Expand Down
11 changes: 11 additions & 0 deletions Sources/Scheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,17 @@ public final class TestScheduler: DateScheduler {
lock.unlock()
}

/// Advances the virtualized clock by the given interval, dequeuing and
/// executing any actions along the way.
///
/// - parameters:
/// - interval: Interval by which the current date will be advanced.
public func advance(by interval: TimeInterval) {
lock.lock()
advance(to: currentDate.addingTimeInterval(interval))
lock.unlock()
}

/// Advances the virtualized clock to the given future date, dequeuing and
/// executing any actions up until that point.
///
Expand Down
9 changes: 9 additions & 0 deletions Tests/ReactiveSwiftTests/SchedulerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ class SchedulerSpec: QuickSpec {
expect(scheduler.currentDate) == Date.distantFuture
expect(string) == "fuzzbuzzfoobar"
}

it("should advance by DispatchTimeInterval same as by TimeInterval") {
let schedulerB = TestScheduler(startDate: startDate)

scheduler.advance(by: .milliseconds(300))
schedulerB.advance(by: 0.3)

expect(scheduler.currentDate).to(equal(schedulerB.currentDate))
}
}
}
}

0 comments on commit 3c448a4

Please sign in to comment.