Asynchronous PureMVC in Python

465 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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.