ArgumentPassingMode: ExcludeEvent
ArgumentPassingMode: IncludeEvent
ArgumentPassingMode: ExcludeEvent
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).
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.
Clear all queued events without dispatching them.
Dispatch an event.
The listeners are called with arguments arg1
, arg2
, etc.
Return true if there is no any event in the event queue, false if there are any events in the event queue.
Put an event into the event queue.
All arguments are copied to internal data structure.
The time complexity is O(1).
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
.
Return true if the dispatcher contains any callback.
Return true if the dispatcher contains callback.
callback can be a callback function, or a handle object.
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).
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.
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).
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()
.
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:
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()
.
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).
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.
Generated using TypeDoc
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.