中断或循环GWT回调响应 [英] Breaking for or loop GWT callback response

查看:63
本文介绍了中断或循环GWT回调响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在 GWT回调的执行方法响应中断for循环.

例如

for (int idx = 0; idx < recordList.getLength(); idx++) {  //Starting ABC FOR LOOP
    ABCDMI.addData(recordList.get(idx), 
                   new DSCallback() {       
                       public void execute(DSResponse response, Object rawData, DSRequest request) {      
                            if(response.getAttribute("UnSuccess") != null && !response.getAttribute("UnSuccess").equalsIgnoreCase("")) {    
                                 break;  //I want to break ABC FOR LOOP here.   
                            }
                   }
}

有人可以帮我吗?

推荐答案

调用异步方法时,您不知道将花费多长时间.在您的示例中,所有这些呼叫几乎都将在同一瞬间发送,但是响应会在将来的任何时候出现,因此不能保证顺序.

When you call an asynchronous method, you dont know how long it will take. In your examples all of these calls will be sent in almost the same instant, but the response would come in any time in the future, so the order is not guaranteed.

当然,您不能中断回调内部的循环,但是您可以处理每次调用完成后从回调内部调用async方法的循环.

Of-course you cannot break a loop inside your callback, but you can handle the loop inside your callback calling the async method from it each time one call finishes.

此示例应适合您的情况,并且所有回调将按顺序执行.

This example should work in your case, and all callbacks would be executed sequentially.

DSCallback myCallBack = new DSCallback() {
  int idx = 0; 
  int length = recordList.getLength();

  public void execute(DSResponse response, Object rawData, DSRequest request) {
    if (++idx < length 
          && (response.getAttribute("UnSuccess") == null 
            || !response.getAttribute("UnSuccess").equalsIgnoreCase(""))) {
      ABCDMI.addData(recordList.get(idx), this);
    }
  }
};

ABCDMI.addData(recordList.get(0), myCallBack);

这篇关于中断或循环GWT回调响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆