PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: tspiva on April 13, 2009, 10:32:34



Title: Request advice on cancelable commands
Post by: tspiva on April 13, 2009, 10:32:34
I was wondering if there is a way to send a notification or something to a command that's currently running.  Here's the setup of what I'm trying to do.

I have a project proxy which does all of the manipulation of the project elements in a work directory.  The user can then save off an archive which is a long running process.  To implement the archive, I created an archive command that is run and has to use things like setTimeout to keep the UI responsive (which really just updates a progress bar) while it's running.

I now need the ability to allow the user to "Cancel" the archive functionality.  However, I can't figure out a way to let the the command know that it needs to be canceled without using any hacks like setting something in the proxy or something.

I considered making a "helper" proxy to just handle saving and loading to/from an archive (they need to be able to cancel loading also) and setting a "cancel" attribute on that guy but I thought I would ask if anyone had any better ideas or if this should've been a helper proxy all along or any other suggestions/comments.

Thanks,
Tracy


Title: Re: Request advice on cancelable commands
Post by: puremvc on April 13, 2009, 01:07:40
This is one of the reasons the Best Practices guide discourages the use of commands for async processes. They simply are not suited to the task.

However your proxy is. It should own the srevice, make the remote call, and have listeners on the service for progress as well as result and fault. If you're not displaying 'real' progress, then use an indeterminate progress bar at the view. Otherwise, broadcast progress notes as they are received at the proxy, and handle them at the mediator that owns the progress bar.

To cancel, simply retrieve the proxy and invoke a method that cancels the service call. QED.

-=Cliff>


Title: Re: Request advice on cancelable commands
Post by: tspiva on April 13, 2009, 01:14:33
Thanks for the quick reply.  I didn't see that in the best practices.. guess I should go back and read it again :)

I'll move it all to the proxy then.

Tracy