Skip to content

Commit 3c448a4

Browse files
authored
Merge pull request #828 from carsten-wenderdel/advance-by-timeinterval
2 parents d861efd + 4dfa99f commit 3c448a4

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# master
22
*Please add new entries at the top.*
33

4+
1. `TestScheduler` can `advance` by `TimeInterval`. (#828)
5+
46
1. Fixed spelling error in `Token` class documentation.
57

68
# 6.6.1

Sources/Scheduler.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,17 @@ public final class TestScheduler: DateScheduler {
563563
lock.unlock()
564564
}
565565

566+
/// Advances the virtualized clock by the given interval, dequeuing and
567+
/// executing any actions along the way.
568+
///
569+
/// - parameters:
570+
/// - interval: Interval by which the current date will be advanced.
571+
public func advance(by interval: TimeInterval) {
572+
lock.lock()
573+
advance(to: currentDate.addingTimeInterval(interval))
574+
lock.unlock()
575+
}
576+
566577
/// Advances the virtualized clock to the given future date, dequeuing and
567578
/// executing any actions up until that point.
568579
///

Tests/ReactiveSwiftTests/SchedulerSpec.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ class SchedulerSpec: QuickSpec {
355355
expect(scheduler.currentDate) == Date.distantFuture
356356
expect(string) == "fuzzbuzzfoobar"
357357
}
358+
359+
it("should advance by DispatchTimeInterval same as by TimeInterval") {
360+
let schedulerB = TestScheduler(startDate: startDate)
361+
362+
scheduler.advance(by: .milliseconds(300))
363+
schedulerB.advance(by: 0.3)
364+
365+
expect(scheduler.currentDate).to(equal(schedulerB.currentDate))
366+
}
358367
}
359368
}
360369
}

0 commit comments

Comments
 (0)