Skip to content

Commit c94c31a

Browse files
authored
Merge pull request #31 from taquitos/timer_fails_on_32_bit
32bit arch crash: timer producer fails when interval is >= 3 seconds
2 parents 3f2daac + 08c6ed8 commit c94c31a

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,20 @@ 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+
if #available(OSX 10.10, *) {
799+
scheduler = QueueScheduler(qos: .default, name: "\(#file):\(#line)")
800+
} else {
801+
scheduler = QueueScheduler(queue: DispatchQueue(label: "\(#file):\(#line)"))
802+
}
803+
804+
let producer = timer(interval: 3, on: scheduler)
805+
producer
806+
.start()
807+
.dispose()
808+
}
809+
796810
it("should release the signal when disposed") {
797811
let scheduler = TestScheduler()
798812
let producer = timer(interval: 1, on: scheduler, leeway: 0)

0 commit comments

Comments
 (0)