Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CallbackList

CallbackList is the fundamental class in quick-event. The other classes EventDispatcher and EventQueue are built on CallbackList.

CallbackList holds a list of callbacks. At the time of the call, CallbackList simply invokes each callback one by one. Consider CallbackList as the signal/slot system in Qt, or the callback function pointer in some Windows APIs (such as lpCompletionRoutine in ReadFileEx). The callback can be any functions.

Nested callback safety

  1. If a callback adds another callback to the callback list during a invoking, the new callback is guaranteed not to be triggered within the same invoking. This is guaranteed by an integer counter. This rule will be broken is the counter is overflowed to zero in a invoking, but this rule will continue working on the subsequence invoking.
  2. Any callbacks that are removed during a invoking are guaranteed not triggered.
export

Hierarchy

  • CallbackList

Index

Constructors

constructor

Accessors

head

tail

Methods

append

  • Add the callback to the callback list.
    The callback is added to the end of the callback list.
    Return a handle object that represents the callback. The handle can be used to remove this callback or to insert additional callbacks before this callback.
    If append is called in another callback during the invoking of the callback list, the new callback is guaranteed not to be triggered during the same callback list invoking.
    The time complexity is O(1).

    memberof

    CallbackList

    Parameters

    Returns CallbackNode

applyDispatch

  • applyDispatch(...args: any[]): void
  • Invoke each callbacks in the callback list.
    The callbacks are called with arguments arg1, arg2, etc.
    Note the arguments are passed in an array, similar to Function.prototype.apply.

    memberof

    CallbackList

    Parameters

    • Rest ...args: any[]

    Returns void

dispatch

  • dispatch(...args: any[]): void
  • Invoke each callbacks in the callback list.
    The callbacks are called with arguments arg1, arg2, etc.

    memberof

    CallbackList

    Parameters

    • Rest ...args: any[]

    Returns void

empty

  • empty(): boolean
  • Return true if the callback list is empty.

    memberof

    CallbackList

    Returns boolean

forEach

  • forEach(func: (callback: Callback) => any): void
  • Apply func to all callbacks.
    The func receives one parameter which is the callback.
    Note: the func can remove any callbacks, or add other callbacks, safely.

    memberof

    CallbackList

    Parameters

    Returns void

forEachIf

  • forEachIf(func: (callback: Callback) => any): boolean
  • Apply func to all callbacks. func must return a boolean value, and if the return value is false, forEachIf stops the looping immediately.
    Return true if all callbacks are invoked, or event is not found, false if func returns false.

    memberof

    CallbackList

    Parameters

    Returns boolean

has

  • Return true if the callback list contains callback.
    callback can be a callback function, or a handle object.

    memberof

    CallbackList

    Parameters

    Returns boolean

hasAny

  • hasAny(): boolean
  • Return true if the callback list contains any callback.

    memberof

    CallbackList

    Returns boolean

insert

  • Insert the callback to the callback list before the callback before. If before is not found, callback is added at the end of the callback list.
    before can be a callback function, or a handle object.
    Return a handle object that represents the callback. The handle can be used to remove this callback or to insert additional callbacks before this callback.
    If insert is called in another callback during the invoking of the callback list, the new callback is guaranteed not to be triggered during the same callback list invoking. The time complexity is O(1).

    memberof

    CallbackList

    Parameters

    Returns CallbackNode

prepend

  • Add the callback to the callback list.
    The callback is added to the beginning of the callback list.
    Return a handle object that represents the callback. The handle can be used to remove this callback or to insert additional callbacks before this callback.
    If prepend is called in another callback during the invoking of the callback list, the new callback is guaranteed not to be triggered during the same callback list invoking.
    The time complexity is O(1).

    memberof

    CallbackList

    Parameters

    Returns CallbackNode

remove

  • Remove the callback from the callback list.
    callback can be a callback function, or a handle object.
    Return true if the callback is removed successfully, false if the callback is not found.
    The time complexity is O(1).

    memberof

    CallbackList

    Parameters

    Returns boolean

Generated using TypeDoc