Visit Mozilla.org

nsIThreadObserver

From MDC

This article covers features introduced in Firefox 3

The nsIThreadObserver interface may be implemented to let an observer implement a layered event queue.

For example, it's possible to overlay processing events for a GUI toolkit on top of the events for a thread:

var NativeQueue;
Observer = {
  onDispatchedEvent(thread) {
    NativeQueue.signal();
  }
  onProcessNextEvent(thread, mayWait, recursionDepth) {
    if (NativeQueue.hasNextEvent()) {
      NativeQueue.processNextEvent();
    }
    while (mayWait && !thread.hasPendingEvent()) {
      NativeQueue.wait();
      NativeQueue.processNextEvent();
    }
  }
};
Warning: The implementation of this interface must be thread safe.

Inherits from: nsISupports

Contents

nsIThreadObserver is defined in xpcom/threads/nsIThreadInternal.idl. It is scriptable and unfrozen (hasn't changed since Mozilla 1.9).

[edit] Method overview

void onDispatchedEvent(in nsIThreadInternal thread);
void onProcessNextEvent(in nsIThreadInternal thread, in boolean mayWait, in unsigned long recursionDepth);
void afterProcessNextEvent(in nsIThreadInternal thread, in unsigned long recursionDepth);

[edit] Methods

[edit] onDispatchedEvent()

Called after an event has been dispatched to the thread. This method may be called from any thread.

Note: It is valid to change the thread's observer during a call to this method.
void onDispatchedEvent(
  in nsIThreadInternal thread
)
[edit] Parameters
thread
The nsIThread on which the event was dispatched.

[edit] onProcessNextEvent()

Called by the nsIThread method processNextEvent() before an event is processed. This method is only called on the target thread.

Note: It is valid to change the thread's observer during a call to this method.
void onProcessNextEvent(
  in nsIThreadInternal thread,
  in boolean mayWait,
  in unsigned long recursionDepth

);

[edit] Parameters
thread
The nsIThread on which the event is going to be processed.
mayWait
true if the method is allowed to block the calling thread. This parameter will be false during thread shutdown, for example.
recursionDepth
The number of calls to ProcessNextEvent() on the call stack in addition to the current call.

[edit] afterProcessNextEvent()

Called by the nsIThread method processNextEvent() after an event is processed. This method is only called on the target thread.

Note: It is valid to change the thread's observer during a call to this method.
void afterProcessNextEvent(
  in nsIThreadInternal thread,
  in unsigned long recursionDepth
)
[edit] Parameters
thread
The nsIThread on which the event was processed.
recursionDepth
The number of calls to ProcessNextEvent() on the call stack in addition to the current call.

[edit] See also