Last active
August 29, 2015 14:17
-
-
Save jearle/6bfe6153a2e36139ef5c to your computer and use it in GitHub Desktop.
SetInterval Implmentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using the setTimeout implementation https://gist.github.com/jearle/6bfe6153a2e36139ef5c | |
public func setInterval(#seconds: Double, callback: CancelFunc) -> EmptyFunc { | |
return setTimeout(seconds: seconds) { | |
callback(setInterval(seconds: seconds, callback)) | |
} | |
} | |
// Example | |
var count = 0 | |
let cancel = setInterval(seconds: 1) { (cancel)->() in | |
count++ | |
println("i will fire every 1 second, until count equals 4") | |
if count == 4 { | |
cancel() | |
} | |
} | |
// cancel() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment