Class
JSTimer
public final class JSTimer
This timer is an abstraction over setInterval
/ clearInterval
and
setTimeout
/ clearTimeout
JavaScript functions. It intentionally doesn't match the JavaScript API, as a special care is
needed to hold a reference to the timer closure and to call JSClosure.release()
on it when the
timer is deallocated. As a user, you have to hold a reference to a JSTimer
instance for it to stay
valid. The JSTimer
API is also intentionally trivial, the timer is started right away, and the
only way to invalidate the timer is to bring the reference count of the JSTimer
instance to zero.
For invalidation you should either store the timer in an optional property and assign nil
to it,
or deallocate the object that owns the timer.
Initializers
init(millisecondsDelay:isRepeating:callback:)
public init(millisecondsDelay: Double, isRepeating: Bool = false, callback: @escaping () -> ())
Creates a new timer instance that calls setInterval
or setTimeout
JavaScript functions for you
under the hood.
Parameters
Name | Type | Description |
---|---|---|
millisecondsDelay | Double |
the amount of milliseconds before the |
isRepeating | Bool |
when |
callback | @escaping () -> () |
the closure to be executed after a given |
Properties
isRepeating
public let isRepeating: Bool
Indicates whether this timer instance calls its callback repeatedly at a given delay.