Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventQueue

EventQueue includes all features of EventDispatcher and adds event queue features.
EventQueue is asynchronous. Events are cached in the queue when EventQueue.enqueue is called, and dispatched later when EventQueue.process is called.
EventQueue is equivalent to the event system (QEvent) in Qt, or the message processing in Windows API.

export

Hierarchy

Index

Constructors

constructor

Properties

Protected argumentsAsArray

argumentsAsArray: boolean

Readonly Static argumentPassingExcludeEvent

argumentPassingExcludeEvent: ArgumentPassingMode = ...

ArgumentPassingMode: ExcludeEvent

static
readonly
memberof

EventDispatcher

Readonly Static argumentPassingIncludeEvent

argumentPassingIncludeEvent: ArgumentPassingMode = ...

ArgumentPassingMode: IncludeEvent

static
readonly
memberof

EventDispatcher

Readonly Static defaultArgumentPassingMode

defaultArgumentPassingMode: ArgumentPassingMode = ...

ArgumentPassingMode: ExcludeEvent

static
readonly
memberof

EventDispatcher

Methods

appendListener

  • Add the callback to the dispatcher to listen to event.
    The listener is added to the end of the listener list.
    Return a handle object which represents the listener. The handle can be used to remove this listener or insert other listener before this listener.
    If appendListener is called in another listener during a dispatching, the new listener is guaranteed not triggered during the same dispatching.
    If the same callback is added twice, it results duplicated listeners.
    The time complexity is O(1).

    memberof

    EventDispatcher

    Parameters

    • event: string | number
    • callback: Callback

    Returns CallbackNode

applyDispatch

  • applyDispatch(args: any[]): void
  • Dispatch an event.
    The listeners are called with arguments arg1, arg2, etc.
    Note the arguments are passed in an array, similar to Function.prototype.apply.

    memberof

    EventDispatcher

    Parameters

    • args: any[]

    Returns void

clearEvents

  • clearEvents(): void
  • Clear all queued events without dispatching them.

    memberof

    EventQueue

    Returns void

dispatch

  • dispatch(...args: any[]): void

empty

  • empty(): boolean
  • Return true if there is no any event in the event queue, false if there are any events in the event queue.

    memberof

    EventQueue

    Returns boolean

enqueue

  • enqueue(...args: any[]): void
  • Put an event into the event queue.
    All arguments are copied to internal data structure.
    The time complexity is O(1).

    memberof

    EventQueue

    Parameters

    • Rest ...args: any[]

    Returns void

forEach

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

    memberof

    EventDispatcher

    Parameters

    • event: string | number
    • func: (callback: Callback) => any

    Returns void

forEachIf

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

    memberof

    EventDispatcher

    Parameters

    • event: string | number
    • func: (callback: Callback) => any

    Returns boolean

hasAnyListener

  • hasAnyListener(event: string | number): boolean

hasListener

insertListener

  • Insert the callback to the dispatcher to listen to event before the listener handle before. If before is not found, callback is added at the end of the listener list.
    before can be a callback function, or a handle object.
    Return a handle object which represents the listener. The handle can be used to remove this listener or insert other listener before this listener.
    If insertListener is called in another listener during a dispatching, the new listener is guaranteed not triggered during the same dispatching.
    The time complexity is O(1).

    memberof

    EventDispatcher

    Parameters

    Returns CallbackNode

peekEvent

  • peekEvent(): any
  • Return a queued event from the queue.
    A queued event is an array with all arguments passed to EventQueue.enqueue.
    If the queue is empty, the function returns null.
    After the function returns, the original even is still in the queue.

    memberof

    EventQueue

    Returns any

prependListener

  • Add the callback to the dispatcher to listen to event.
    The listener is added to the beginning of the listener list.
    Return a handle object which represents the listener. The handle can be used to remove this listener or insert other listener before this listener.
    If prependListener is called in another listener during a dispatching, the new listener is guaranteed not triggered during the same dispatching.
    The time complexity is O(1).

    memberof

    EventDispatcher

    Parameters

    • event: string | number
    • callback: Callback

    Returns CallbackNode

process

  • process(): void
  • Process the event queue. All events in the event queue are dispatched once and then removed from the queue.
    The function returns true if any events were processed, false if no event was processed.
    Any new events added to the queue during process() are not dispatched during current process().

    memberof

    EventQueue

    Returns void

processIf

  • processIf(func: (...args: any[]) => boolean): void
  • Process the event queue. Before processing an event, the event is passed to func and the event will be processed only if func returns true.
    func takes exactly the same arguments as EventQueue.enqueue, and returns a boolean value.
    processIf returns true if any event was dispatched, false if no event was dispatched.
    processIf has some good use scenarios:

    1. Process certain events. For example, in a GUI application, the UI related events may be only desired to processed by one module.
    2. Process the events until certain time. For example, in a game engine, the event process may be limited to only several milliseconds, the remaining events will be process in next game loop.
    memberof

    EventQueue

    Parameters

    • func: (...args: any[]) => boolean
        • (...args: any[]): boolean
        • Parameters

          • Rest ...args: any[]

          Returns boolean

    Returns void

processOne

  • processOne(): void
  • Process one event in the event queue. The first event in the event queue is dispatched once and then removed from the queue.
    The function returns true if one event was processed, false if no event was processed.
    Any new events added to the queue during processOne() are not dispatched during current processOne().

    memberof

    EventQueue

    Returns void

removeListener

  • removeListener(event: string | number, handle: undefined | null | CallbackNode | Callback): boolean
  • Remove the listener callback which listens to event from the dispatcher.
    callback can be a callback function, or a handle object.
    Return true if the listener is removed successfully, false if the listener is not found.
    The time complexity is O(1).

    memberof

    EventDispatcher

    Parameters

    Returns boolean

takeEvent

  • takeEvent(): any
  • Return an event from the queue and remove the original event from the queue.
    If the queue is empty, the function returns null.
    After the function returns, the original even is removed from the queue.

    memberof

    EventQueue

    Returns any

Generated using TypeDoc