阻止方法调用,直到异步调用完成GWT平台 [英] Prevent method call until Async Call Completes GWT-Platform

查看:141
本文介绍了阻止方法调用,直到异步调用完成GWT平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的GWT-Platform应用程序中,我实现了一步从服务器获取数据的方法,下一步依赖于它。我想阻止我的方法进一步执行代码,直到Async调用完成。



应该是简单但我找不到方法。

解决方案

我认为您错过了关于网络异步的观点。

在异步调用完成之前阻止客户端代码的执行并不被认为是好的做法(它相当于一种反模式)。

因此,不要在完成异步代码之前阻止执行,请执行以下操作:


  1. 在您的异步代码完成时创建在全局Eventbus上触发的事件

  2. 在您的某个演示者中为此事件附加处理程序

  3. 启动异步代码
  4. 显示加载指示器 当异步调用完成时,隐藏加载指示器并在事件总线上触发事件
  5. li>
  6. 处理之前创建的Handler中的下一步。


In my GWT-Platform application I have implemented method in which one step is to fetch data from server and next step is dependent on it. I want to prevent my method for further execution of the code until the Async call completes.

Should be something simple but I am not finding a way.

解决方案

I think you are missing the point about the web being asynchronous.

It is not considered good practice (it is rather an anti-pattern) to block the execution of your client side code until the async call is finished.

So instead of blocking the execution until your async code is finished do following:

  1. Create a Event which is fired on the global Eventbus when your async code is finished
  2. Attach a Handler for this event in one of your Presenters
  3. Start the async code
  4. Show a loading indicator
  5. When the async call is finished hide the loading indicator and fire the Event on the Eventbus
  6. Handle the next step in the Handler you created before.

这篇关于阻止方法调用,直到异步调用完成GWT平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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