FLEX Cairngorm 命令...奇怪的行为
在尝试解决序列化 cairngorm 命令执行的问题时,我尝试完全绕过事件分派并简单地实例化我想要执行的命令,然后调用它的执行方法。在此方法中,有一个对委托的调用,该委托调用执行 HTTPService.send 操作的 ServiceUtils...
现在,这些命令应该按照我调用它们的顺序运行。 并且,由于服务器 (RAILS) 只有一个,因此所有请求都应以相同的顺序返回。 事实并非如此..顺序因不同的执行而异..为什么?!?
while trying to solve my problems in serializing the execution of cairngorm commands, I tried to bypass completely the event dispatching and simply instantiated the command I wanted to execute, then called it's execute method. In this method there's a call to a delegate that calls ServiceUtils that performs the HTTPService.send thing...
Now, those commands should be run in the exact order I call them.
And, since the server (RAILS) is only one, all requests should return in the same order.
This isn't so.. the order varies upon different executions.. why?!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅仅因为您按特定顺序发送请求并不意味着响应将按该顺序返回。 HTTPService 调用是异步的。例如,假设同时发送以下三个请求:
请求 1(服务器需要 4 秒处理)
请求 2(处理时间为 0.5 秒)
请求 3(处理需要 2 秒)
假设网络速度恒定(并且许多其他环境问题恒定),您将首先收到请求 2 的响应,然后是请求 3,然后是请求 1。
如果您需要调用他们连续,你应该做这样的事情:
希望有帮助。
Just because you send requests in a certain order doesn't mean the responses will return in that order. HTTPService calls are asynchronous. For example, assume the following three requests are sent at the same time:
Request 1 (takes 4 seconds on the server to process)
Request 2 (takes 0.5 seconds to process)
Request 3 (takes 2 seconds to process)
Assuming network speed is constant (and a lot of other environment issues being constant), you will get the response for Request 2 back first, then Request 3, then Request 1.
If you need to call them in serial, you should do something like this:
Hope that helps.
RJ的回答很好地涵盖了这一点。只是补充一下:
您的命令将通过您使用的服务创建异步请求。如果要“模拟”命令的同步执行,则必须在前一个命令请求的 resultHandler 中执行后续命令。
尽管这可能并不总是最干净的做事方式,但它可能适合您的场景。我需要有关服务呼叫性质和一般应用程序的更多信息来拨打电话,无论这是否是最适合您的方法。
哈特哈,
斯里
RJ's answer covers it very well. Just to add to it:
Your commands will create asynchronous requests via the services you use. If you want to "simulate" synchronous execution of commands, the subsequent command will have to be executed in the resultHandler of the previous commands request.
Although this may not always be the cleanest way of doing things, it may be suitable for your scenario. I'll need more information about the nature of service calls and the app in general to make a call whether this is the best method for you or not.
HTH,
Sri