阻止方法调用,直到异步调用完成GWT平台 [英] Prevent method call until Async Call Completes GWT-Platform
问题描述
在我的GWT-Platform应用程序中,我实现了一步从服务器获取数据的方法,下一步依赖于它。我想阻止我的方法进一步执行代码,直到Async调用完成。
应该是简单但我找不到方法。
我认为您错过了关于网络异步的观点。
在异步调用完成之前阻止客户端代码的执行并不被认为是好的做法(它相当于一种反模式)。
因此,不要在完成异步代码之前阻止执行,请执行以下操作:
- 在您的异步代码完成时创建在全局Eventbus上触发的事件
- 在您的某个演示者中为此事件附加处理程序
- 启动异步代码
- 显示加载指示器 当异步调用完成时,隐藏加载指示器并在事件总线上触发事件
li>
- 处理之前创建的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:
- Create a Event which is fired on the global Eventbus when your async code is finished
- Attach a Handler for this event in one of your Presenters
- Start the async code
- Show a loading indicator
- When the async call is finished hide the loading indicator and fire the Event on the Eventbus
- Handle the next step in the Handler you created before.
这篇关于阻止方法调用,直到异步调用完成GWT平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!