Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid over resume / suspend dispatch timer #22

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Avoid over resume / suspend dispatch timer
  • Loading branch information
fiveze committed Apr 19, 2018
commit 97ed9b55333cb96a15c6595007fcc976ab02af42
10 changes: 6 additions & 4 deletions Sources/Repeat/Repeater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,11 @@ open class Repeater : Equatable {
/// Destroy current timer
private func destroyTimer() {
self.timer?.setEventHandler(handler: nil)
//self.timer?.resume()
self.timer?.cancel()
self.timer?.resume()

if state == .paused || state == .finished {
self.timer?.resume()
}
}

/// Create and schedule a timer that will call `handler` once after the specified time.
Expand Down Expand Up @@ -364,9 +366,10 @@ open class Repeater : Equatable {
/// Pause a running timer. If timer is paused it does nothing.
@discardableResult
public func pause() -> Bool {
guard state != .paused else {
guard state != .paused && state != .finished else {
return false
}

return self.setPause(from: self.state)
}

Expand Down Expand Up @@ -417,7 +420,6 @@ open class Repeater : Equatable {

deinit {
self.observers.removeAll()
self.pause()
self.destroyTimer()
}

Expand Down