Skip to content

Commit

Permalink
Fixed Timer(timeInterval:,repeats:,block:) not accounting timeInterva…
Browse files Browse the repository at this point in the history
…l for the first fire date. (#196)

https://github.com/OpenCombine/OpenCombine/blob/master/Sources/OpenCombineFoundation/Helpers/Portability.swift#L58-L64

It looks like this was a typo/something overlooked, but basically, this `fire: Date()` breaks at least every timer publisher like `Timer.publish(every: timeInterval, on: .main, in: .default)`, as it basically results in the *first* event fired immediately vs in timeInterval. (Just in case, no, Combine does not fire that extra event).

* Fixed Timer(timeInterval:,repeats:,block:) not accounting timeInterval for the first fire date.

* Fixed Danger warning about line length.
  • Loading branch information
grigorye committed Jan 29, 2021
1 parent 911a4e1 commit 3d61bf8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/OpenCombineFoundation/Helpers/Portability.swift
Expand Up @@ -60,7 +60,12 @@ internal struct Timer {
repeats: Bool,
block: @escaping (Timer) -> Void
) {
self.init(fire: Date(), interval: timeInterval, repeats: repeats, block: block)
self.init(
fire: Date() + timeInterval,
interval: timeInterval,
repeats: repeats,
block: block
)
}

internal var tolerance: TimeInterval {
Expand Down

0 comments on commit 3d61bf8

Please sign in to comment.