Skip to content

Commit 0893ed0

Browse files
author
Joshua Liebowitz
committed
on 32bit arch timer producer fails when interval is > 2 seconds
nanos conversion overflows on 32 bit devices because new dispatch API takes an Int and not Int64
1 parent 3f2daac commit 0893ed0

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ matrix:
2222
- XCODE_SDK=iphonesimulator
2323
- XCODE_ACTION="build-for-testing test-without-building"
2424
- XCODE_DESTINATION="platform=iOS Simulator,name=iPhone 6s"
25+
env:
26+
- XCODE_SDK=iphonesimulator
27+
- XCODE_ACTION="build-for-testing test-without-building"
28+
- XCODE_DESTINATION="platform=iOS Simulator,name=iPhone 5"
2529
- xcode_scheme: ReactiveSwift-tvOS
2630
env:
2731
- XCODE_SDK=appletvsimulator

Sources/Scheduler.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,16 @@ public final class QueueScheduler: DateSchedulerProtocol {
264264
precondition(interval >= 0)
265265
precondition(leeway >= 0)
266266

267-
let nsecInterval = interval * Double(NSEC_PER_SEC)
268-
let nsecLeeway = leeway * Double(NSEC_PER_SEC)
267+
let msecInterval = interval * 1000
268+
let msecLeeway = leeway * 1000
269269

270270
let timer = DispatchSource.makeTimerSource(
271271
flags: DispatchSource.TimerFlags(rawValue: UInt(0)),
272272
queue: queue
273273
)
274274
timer.scheduleRepeating(wallDeadline: wallTime(with: date),
275-
interval: .nanoseconds(Int(nsecInterval)),
276-
leeway: .nanoseconds(Int(nsecLeeway)))
275+
interval: .milliseconds(Int(msecInterval)),
276+
leeway: .milliseconds(Int(msecLeeway)))
277277
timer.setEventHandler(handler: action)
278278
timer.resume()
279279

Tests/ReactiveSwiftTests/SignalProducerSpec.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,14 @@ class SignalProducerSpec: QuickSpec {
793793
expect(dates) == [tick1, tick2, tick3]
794794
}
795795

796+
it("shouldn't overflow on a real scheduler") {
797+
let scheduler = QueueScheduler()
798+
let producer = timer(interval: 3, on: scheduler)
799+
let disposable = producer.start()
800+
801+
disposable.dispose()
802+
}
803+
796804
it("should release the signal when disposed") {
797805
let scheduler = TestScheduler()
798806
let producer = timer(interval: 1, on: scheduler, leeway: 0)

0 commit comments

Comments
 (0)