Greetings.
Hello. I am relatively new to PureMVC. I have some questions about ICommand, AsyncCommand and related elements. I'm sorry this post is so long. I wanted to make certain I gave a full accounting of the notification issue I asking for suggestions about.
I have worked through the Sequential demo and understand how it works. No questions about it. My questions are more about error detection and process control during success/fail states for asynchronous command events.
My goal: I need "transactionable" AsyncCommands which can detect successful and unsuccessful results of the execution of asynchronous mediator function calls. This means (or seems to mean) I need a ICommand class/solution that executes a asynchronous function on a mediator and waits for the asynchronous results of that mediator action to be delivered to the Command in an asynchronous manner.
Background: I have a series of commands that will be executed in an AsyncMacroCommand derivation. If one AsyncCommand registers failure, I need to detect this and (potentially) abort the entire series of commands, retry the failed command and/or ignore the error entirely and continue executing steps. The success use case is already working.
Pseudo Call Diagram:
MyAsyncCommand.execute()
+--(calls)--> MyMediator's function1()
{
// async method invoked
executes/starts a non-PureMVC asynchronous task
}
MyMediator's function2( some event )
{
// async method results delivered here
// Success/fail of asynch. MyMediator.function1() execution.
// Set some state so MyAsyncCommand knows the status
// but how ???
/
} /
/
... Magic occurs here ... /
/
MyAsyncCommand.resultsFunction( some event )
{
if ( some event == success )
sendNotificiation( MyAsyncCommand.success )
else
sendNotificiation( MyAsyncCommand.failed )
commandComplete();
}
My specific question: how can I get a ICommand/AsyncCommand to confirm that an asynchronous action, performed by a Mediator, was completed un/successfully?
Workaround/"Bad Idea" #1: I could setup the AsyncCommand on a timer and keep asking the mediator for status. I would really rather not that this direction.
While ICommand can send notification events, it can not receive notification events. In the problem I am trying to solve, I have asynchronous actions which are invoked from a mediator because of an AsyncCommmand. However, I need for the AsyncCommmand to only finish execution (ie. call commandComplete()) when it has confirmed the mediator's asynchronous task has completed successfully or unsuccessfully.
If a ICommand supported the handleNotification() method, then I'd be able to listen of status notifications from the Mediator this way.
Workaround/"Bad Idea" #2: create a hybrid IMediator/ICommand that can execute behaviors and listen for the results. I'd rather not reinvent this complicated wheel if don't have to.
What's the correct approach here?
Mike B.
PS I have working code for all but the success/failure notification from the Mediator to a AsyncCommand. Just need a (correct) "pattern" for this problem set to integrate.