使用 XPCOM 回调
我想实现类似于计时器组件的观察者模式。不是按时间到期调用回调,而是从系统事件(如创建新文件或收到新电子邮件等)调用作为主题观察者的回调。我尝试在组件 XPCOM 中使用 nsIObserverService,但组件中的函数似乎无法使用 NotifyObservers 调用 JavaScript 中的观察者。 NotifyObservers 仅在从 JavaScript 调用时才起作用。
提前致谢
I would like to implement the observer pattern similar to Timer component. Instead of calling a callback by time expiration, the callbacks that are observers of a topic would be called from system events (like new file created, or a new e-mail received, etc.). I tried using nsIObserverService in the component XPCOM, but it seems that functions from component aren't able to call observers in JavaScript by using NotifyObservers. The NotifyObservers only works when is called from JavaScript.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Example::Example
始终在主线程上运行(因为它是由您的脚本创建的)。因此它永远不会创建观察者服务的代理。但是从Ex::Run
对Example::Call
的调用发生在后台线程上,我认为在这种情况下对NotifyObservers
的调用返回NS_ERROR_UNEXPECTED
(您忽略它)。Example::Example
always runs on the main thread (because it's being created by your script). So it never creates a proxy to the observer service. But the call toExample::Call
fromEx::Run
happens on the background thread, and I think in this case the call toNotifyObservers
returnsNS_ERROR_UNEXPECTED
(which you ignore).