Kron

public class Kron : NSObject

Kron is a NSTimer manager offering 4 modes through a unified api. Kron takes care of the involved implementation of NSTimers while ensuring a proper memory management with no extra effort:

  1. Kron.debounce: Calls immediatly and reject calls until time out elapses
  2. Kron.debounceLast: As debounce but also performs the last call after time out
  3. Kron.idle: Performs the last call after not being called during the timeout interval
  4. Kron.watchdog: As idle but allowing to be canceled with watchDogCancel
  • Creates both a debounce and idle idle timer.

    • The function will debounce actions as defined in interval
    • Additionally will ensure to perform the last call after timeout
    • Timer will be reset if called again with the same KronKey

    Declaration

    Swift

    public static func debounceLast(
        timeOut interval:Double,
        resetKey aKey:KronKey,
        context:Any? = nil,
        action:@escaping KronClosure)

    Parameters

    interval

    the timeOut interval

    aKey

    an String or Class

    context

    any Struct or Class. (Internally wraped as a weak reference)

    action

    closure called on timeout

  • Creates a debounce timer.

    • The function will debounce actions as defined in interval
    • Timer will be reset if called again with the same KronKey

    Declaration

    Swift

    public static func debounce(
        timeOut interval:Double,
        resetKey aKey:KronKey,
        context:Any? = nil,
        action:@escaping KronClosure)

    Parameters

    interval

    the timeOut interval

    aKey

    an String or Class

    context

    any Struct or Class. (Internally wraped as a weak reference)

    action

    closure called on timeout

  • Creates a watchdog timer.

    • Use watchdogCancel to early abort the timer.
    • The function will be called after timeout.
    • Timer will be reset if called again with the same KronKey

    Declaration

    Swift

    public static func watchDog(
        timeOut interval:Double,
        resetKey aKey:KronKey,
        context:Any? = nil,
        action:@escaping KronClosure)

    Parameters

    interval

    the timeOut interval

    aKey

    an String or Class

    context

    any Struct or Class. (Internally wraped as a weak reference)

    action

    closure called on timeout

  • Used to cancel a watchdog timer

    Declaration

    Swift

    public static func watchDogCancel(key aKey: KronKey)

    Parameters

    aKey

    any active timer KronKey

  • Creates an idle timer.

    • The function will be called after timeout.
    • Timer will be reset if called again with the same KronKey

    Declaration

    Swift

    public static func idle(
        timeOut interval:Double,
        resetKey aKey:KronKey,
        context:Any? = nil,
        action:@escaping KronClosure)

    Parameters

    interval

    the timeOut interval

    aKey

    an String or Class

    context

    any Struct or Class. (Internally wraped as a weak reference)

    action

    closure called on timeout

  • Creates both a debounce and idle idle timer.

    • The function will debounce actions as defined in interval
    • Additionally will ensure to perform the last call after timeout
    • Timer will be reset if called again with the same KronKey

    Declaration

    Swift

    public func debounceLast(
        timeOut interval:Double,
        resetKey aKey:KronKey,
        context:Any? = nil,
        action:@escaping KronClosure)

    Parameters

    interval

    the timeOut interval

    aKey

    an String or Class

    context

    any Struct or Class. (Internally wraped as a weak reference)

    action

    closure called on timeout

  • Creates a debounce timer.

    • The function will debounce actions as defined in interval
    • Timer will be reset if called again with the same KronKey

    Declaration

    Swift

    public func debounce(
        timeOut interval:Double,
        resetKey aKey:KronKey,
        context:Any? = nil,
        _ action:@escaping KronClosure)

    Parameters

    interval

    the timeOut interval

    aKey

    an String or Class

    context

    any Struct or Class. (Internally wraped as a weak reference)

    action

    closure called on timeout

  • Creates a watchdog timer.

    • Use watchdogCancel to early abort the timer.
    • The function will be called after timeout.
    • Timer will be reset if called again with the same KronKey

    Declaration

    Swift

    public func watchDog(
        timeOut interval:Double,
        resetKey aKey:KronKey,
        context:Any? = nil,
        _ action:@escaping KronClosure)

    Parameters

    interval

    the timeOut interval

    aKey

    an String or Class

    context

    any Struct or Class. (Internally wraped as a weak reference)

    action

    closure called on timeout

  • Used to cancel a watchdog timer

    Declaration

    Swift

    public func watchDogCancel(key aKey: KronKey)

    Parameters

    aKey

    any active timer KronKey

  • Creates an idle timer.

    • The function will be called after timeout.
    • Timer will be reset if called again with the same KronKey

    Declaration

    Swift

    public func idle(
        timeOut interval:Double,
        resetKey aKey:KronKey,
        context:Any? = nil,
        _ action:@escaping KronClosure)

    Parameters

    interval

    the timeOut interval

    aKey

    an String or Class

    context

    any Struct or Class. (Internally wraped as a weak reference)

    action

    closure called on timeout