From 77a8d43499ef858f5948830acea58f4c8615fb04 Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Thu, 16 Sep 2021 09:03:50 +0300 Subject: [PATCH] refactor: add protocol functions --- .../TITimer/Sources/TITimer/Protocols/ITimer.swift | 6 ++++++ .../Sources/TITimer/Sources/TITimer/TITimer.swift | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/TIFoundationUtils/Sources/TITimer/Sources/TITimer/Protocols/ITimer.swift b/TIFoundationUtils/Sources/TITimer/Sources/TITimer/Protocols/ITimer.swift index 17757062..7482795b 100644 --- a/TIFoundationUtils/Sources/TITimer/Sources/TITimer/Protocols/ITimer.swift +++ b/TIFoundationUtils/Sources/TITimer/Sources/TITimer/Protocols/ITimer.swift @@ -36,4 +36,10 @@ public protocol ITimer: Invalidatable { // Запустить работу таймера func start(with interval: TimeInterval) + + // Приостановить работу таймера + func pause() + + // Возобновить работу таймера + func resume() } diff --git a/TIFoundationUtils/Sources/TITimer/Sources/TITimer/TITimer.swift b/TIFoundationUtils/Sources/TITimer/Sources/TITimer/TITimer.swift index 90ca49b8..9505065e 100644 --- a/TIFoundationUtils/Sources/TITimer/Sources/TITimer/TITimer.swift +++ b/TIFoundationUtils/Sources/TITimer/Sources/TITimer/TITimer.swift @@ -79,10 +79,18 @@ public final class TITimer: ITimer { } public func pause() { + guard isRunning else { + return + } + invalidate() } public func resume() { + guard !isRunning else { + return + } + createTimer(with: interval) }