Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: How to route dependent async calls with SQLite?  (Read 6601 times)
asciiman
Newbie
*
Posts: 1


View Profile Email
« on: March 15, 2010, 01:18:52 »

I'm having a hard time knowing how to route multiple asynchronous proxy calls that feed each other data.  I've read about state machines, asynchronous commands, and handling everything within the model.  I'm not sure what the best solution is for my situation.  Hopefully it's simple, and I can learn something new.

I've got two proxies: one for managing changes to a vendor, and one to manage changes to an activity.  It's also possible to link an existing vendor to an existing activity.  This is done in the activity proxy by taking the id for the vendor, the id for the activity, and storing them in a table.  Both proxies are proxies for a local SQLite db.

In the view, I want to be able to create a new vendor and have it linked to an activity with one user action.  The steps are:
1) Create the new vendor and submit it to the db
2) Get the vendor ID from the db
3) Link the new vendor ID with the ID of the activity the user was viewing when the whole process began

I've thought about using async commands for the whole operation.  I'd store the activity ID and the new vendor info in the body.  The first subcommand would call the vendor proxy to add the vendor and send along a callback function which the vendor proxy would call when it's done.  The proxy would pass back the id of the new vendor.  Then the second command would somehow get the vendor ID from the first command and link the vendor id with the original activity id.

With this approach, first of all I'm stuck about how to pass the retrieved vendor id from the first command to the second.  Secondly, this whole operation seems like it leans on the side of domain logic, and should therefore be contained completely in the model.

So, my second approach is to do just that.  In the activity proxy I created a public function to add a new vendor and link it with an activity.  It's passed all the info for a new vendor and the id for the activity to add it to.  It makes a call to the vendor proxy to add the vendor.  In that call it passes along a callback function for when the operation is complete.  The callback is executed and from here I can get the new vendor id.  However, how can I get the original activity id now?  There is a chance that the original function can be called multiple times, and I need to link the correct activity id with the returned vendor id.  It seems mistaken to assume that calls to the db will return in any particular order.  I considered the idea of sending a token along with the vendor id call, but as far as I can tell SQLLite doesn't have a notion of tokens.

This seems like a common situation.  Why am I having such a tough time with it?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 17, 2010, 01:05:50 »

I think a little clarification of the use case(s) is needed. I believe the StateMachine will be your best answer, as it totally decouples the activities that occur before and after async operations and allows passing of data frome one state to the next.

-=Cliff>
Logged
Pages: [1]
Print