- Create a AsyncToken in Service method
- Return it to the command
- Retain it with service for the time when we shall get the result
- As we get the result in result handler of service, use AsyncToken to return the result to command.
- Get the responders form the AsyncToken responders array and hand over the result or fault to these.
- The result or fault will be communicated to the Command result or error handler methods.
Here point is that how AsyncToken will get the responder for command. The process under the hood is that as Service return the AsyncToken to Command, and command return the same object further. Parsley framework will capture the return value, create a Responder with Command's result and fault methods and add it to the AsyncToken. So when we are accessing the first responder from AsyncToken, this is the same responder which Parsley has added automatically.
AsyncToken.responders[0].result(resultObject);
Or
AsyncToken.responders[0].fault(faultObject);
Keep in mind, if you are not returning the AsyncToken from the service and hence from the Command, and if the command is dynamic; Parsley will remove the Command reference from the context as soon as control will return from the execute method. Otherwise it will retain it till it gets the result or fault call on AsyncToken>responder.
Another point is that any object in Parsley is not able to capture the event if it has already been removed from the context. So any object should be alive with Parsley context to be a part of framework and to be managed by Parsley, only then it will be eligible for the events and other facilities.
0 comments:
Post a Comment