Python 中的异步 PureMVC

发布于 2024-09-13 21:15:22 字数 963 浏览 5 评论 0原文

此处获取以下代码,从底部的缩短版本开始,存在此代理:

class DataModelProxy(puremvc.patterns.proxy.Proxy):
    NAME = "DataModelProxy"

    def __init__(self):
        super(DataModelProxy, self).__init__(DataModelProxy.NAME, [])
        self.realdata = Data()
        self.sendNotification(AppFacade.DATA_CHANGED, self.realdata.data)

    def setData(self, data):
        self.realdata.data = data
        print "setData (model) to", data
        self.sendNotification(AppFacade.DATA_CHANGED, self.realdata.data)

从 PureMVC Python 文档中引用 此处 ,它说:

代理可能只是管理对本地数据对象的引用,在这种情况下与其交互可能涉及以同步方式设置和获取其数据。

代理类还用于封装应用程序与远程服务的交互以保存或检索数据,在这种情况下,我们采用异步习惯用法;在代理上设置数据(或调用方法),并侦听代理从服务检索数据时发送的通知。

如果是这种情况,当我要检索昂贵且耗时的数据时,如何让我的代理异步执行?

Taking the following code from here, from the shortened version at the bottom, exists this proxy:

class DataModelProxy(puremvc.patterns.proxy.Proxy):
    NAME = "DataModelProxy"

    def __init__(self):
        super(DataModelProxy, self).__init__(DataModelProxy.NAME, [])
        self.realdata = Data()
        self.sendNotification(AppFacade.DATA_CHANGED, self.realdata.data)

    def setData(self, data):
        self.realdata.data = data
        print "setData (model) to", data
        self.sendNotification(AppFacade.DATA_CHANGED, self.realdata.data)

Quoting from here from the PureMVC Python docs, it says:

A Proxy might simply manage a reference to a local data object, in which case interacting with it might involve setting and getting of its data in synchronous fashion.

Proxy classes are also used to encapsulate the application's interaction with remote services to save or retrieve data, in which case, we adopt an asyncronous idiom; setting data (or calling a method) on the Proxy and listening for a Notification to be sent when the Proxy has retrieved the data from the service.

If this is the case, how can I get my proxy to perfrom asynchronously when I have expensive and time consuming data to retreive?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

权谋诡计 2024-09-20 21:15:22

你的问题真的很有趣。我刚刚学习了PureMVC,这只是我的想法,未经证实。

在 puremvc.patterns.observer 中使用 Notifier 怎么样?或者更简单的方法,在异步数据检索函数中,在过程完成时发送通知:) 这种方式听起来很像 PureMVC 方式:通过通知进行通信。我猜唯一关心的是确保通知机制是线程安全的。

还有一个想法。您可以尝试实用程序 - AS3/启动管理器背后的想法。

Your question is really interesting. I just studied PureMVC and it is just my thought, not proven.

How about making use of Notifier in puremvc.patterns.observer? Or much easier way, in your asynchronous data-retrieving function, send a notification when the process is done :) That way sounds much PureMVC-way: communication by notifications. The only concern I guess is to make sure the notification mechanism is thread-safe.

One more idea. You can try the idea behind Utility - AS3 / Startup Manager.

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