Skip to content

eonist/SimpleTimer

Repository files navigation

SimpleTimer:

mit platform platform Lang SPM compatible codebeat badge Tests

Features:

  • Local scoped timer
  • Chainable
  • One liners
  • Uses regular callbacks

Installation:

  • SPM: url: "github/eonist/SimpleTimer.git" .branch: "master"
  • Manual: Copy paste: SimplerTimer.swift

Note:

  • Mac apps go into inactive state after 60 secs. Then this timer will slow down.

Example:

SimpleTimer(interval: 3, repeats: true){print("tick")}.start()//Ticks every 3 seconds

Example:

var idx: Int = 0
/**
 * A Timer based on GCD (More reliable as it doesn't freeze if main thread is frozen)
 * - Note: The can also be used: .seconds(Int), .microseconds(Int) and .nanoseconds(Int)
 */
func timerGCD() -> () {
	DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
		Swift.print("tick: idx\(self.idx)")
		self.idx += 1
		if self.idx < 10 {self.timerGCD()}//stop at 1sec
	}
}

About

Timer with regular callbacks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages