FLEX Cairngorm 命令...奇怪的行为

发布于 2024-08-17 09:22:54 字数 231 浏览 6 评论 0原文

在尝试解决序列化 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情何以堪。 2024-08-24 09:22:54

仅仅因为您按特定顺序发送请求并不意味着响应将按该顺序返回。 HTTPService 调用是异步的。例如,假设同时发送以下三个请求:

请求 1(服务器需要 4 秒处理)
请求 2(处理时间为 0.5 秒)
请求 3(处理需要 2 秒)

假设网络速度恒定(并且许多其他环境问题恒定),您将首先收到请求 2 的响应,然后是请求 3,然后是请求 1。

如果您需要调用他们连续,你应该做这样的事情:

protected function doWork():void {
    request1.send();
}

protected function onRequest1Complete(e:ResultEvent):void {
    request2.send();
}

protected function onRequest2Complete(e:ResultEvent):void {
    request3.send();
}

protected function onRequest3Complete(e:ResultEvent):void {
    // you are done at this point
}

...

<mx:HTTPService id="request1" url="http://example.com/service1" result="onRequest1Complete(event)" />
<mx:HTTPService id="request2" url="http://example.com/service2" result="onRequest2Complete(event)" />
<mx:HTTPService id="request3" url="http://example.com/service3" result="onRequest3Complete(event)" />

希望有帮助。

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:

protected function doWork():void {
    request1.send();
}

protected function onRequest1Complete(e:ResultEvent):void {
    request2.send();
}

protected function onRequest2Complete(e:ResultEvent):void {
    request3.send();
}

protected function onRequest3Complete(e:ResultEvent):void {
    // you are done at this point
}

...

<mx:HTTPService id="request1" url="http://example.com/service1" result="onRequest1Complete(event)" />
<mx:HTTPService id="request2" url="http://example.com/service2" result="onRequest2Complete(event)" />
<mx:HTTPService id="request3" url="http://example.com/service3" result="onRequest3Complete(event)" />

Hope that helps.

留一抹残留的笑 2024-08-24 09:22:54

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文