nsIThreadObserver 编辑

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

The implementation of this interface must be thread safe.

xpcom/threads/nsIThreadInternal.idlScriptable Please add a summary to this article.   Last changed in Gecko 1.9 (Firefox 3)

Inherits from: nsISupports

Method overview

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

Methods

afterProcessNextEvent()

Called by the nsIThread method nsIThread.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
);
Parameters
thread
The nsIThread on which the event was processed.
recursionDepth
The number of calls to nsIThread.ProcessNextEvent() on the call stack in addition to the current call.

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
);
Parameters
thread
The nsIThread on which the event was dispatched.

onProcessNextEvent()

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

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
);
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.
recursionDepth
The number of calls to nsIThread.ProcessNextEvent() on the call stack in addition to the current call.

Example

It is 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();
    }
  }
};

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:44 次

字数:6079

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文