Skip to content

Instantly share code, notes, and snippets.

@jearle
Last active August 29, 2015 14:17
Show Gist options
  • Save jearle/6bfe6153a2e36139ef5c to your computer and use it in GitHub Desktop.
Save jearle/6bfe6153a2e36139ef5c to your computer and use it in GitHub Desktop.
SetInterval Implmentation
// 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