阻止方法调用,直到异步调用完成GWT平台

编程入门 行业动态 更新时间:2024-10-23 22:32:17
本文介绍了阻止方法调用,直到异步调用完成GWT平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的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平台

    本文发布于:2023-11-28 06:48:01,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:方法   平台   GWT

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!