ActionScript 3 AsyncToken 实现

发布于 2024-07-25 13:30:15 字数 98 浏览 3 评论 0原文

寻找有关如何实现返回 AsyncToken 的方法的示例或文档链接。

请注意,这不是关于使用/消耗返回 AsyncToken 的方法! 我想自己写这样的方法。

Looking for an example or documentation links as to how to implement a method returning AsyncToken.

Note this is not about using/consuming a method returning AsyncToken! I wish to write such methods myself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

热血少△年 2024-08-01 13:30:15

实现返回 AsyncToken 的方法很简单:

function doStuffLater():AsyncToken {
    var token:AsyncToken = new AsyncToken(null);

    // This method will randomly call the responder's 'result' or 'fault'
    // handler.
    function doStuff() {
        var response:String = (Math.random() > 0.5)? "result" : "fault";
        for each (responder:IResponder in (token.responders || [])) {
            // rememeber: this is equivilent to
            // responder.result(...) or responder.fault(...)
            responder[response]("Got a result!");
        }
    }

    setTimeout(doStuff, 1000);

    return token;
}

请注意,您实际上不能使用 applyResultapplyFault 方法,因为它们向响应者传递一个 Event,当响应者排除结果或故障对象时。

Implementing a method that returns an AsyncToken is simple:

function doStuffLater():AsyncToken {
    var token:AsyncToken = new AsyncToken(null);

    // This method will randomly call the responder's 'result' or 'fault'
    // handler.
    function doStuff() {
        var response:String = (Math.random() > 0.5)? "result" : "fault";
        for each (responder:IResponder in (token.responders || [])) {
            // rememeber: this is equivilent to
            // responder.result(...) or responder.fault(...)
            responder[response]("Got a result!");
        }
    }

    setTimeout(doStuff, 1000);

    return token;
}

Note that you can't actually use the applyResult and applyFault methods, because they pass the responders an Event, when the responder except the result or fault object.

万水千山粽是情ミ 2024-08-01 13:30:15

Swiz 框架的 TestUtil 类有一些非常酷的方法来模拟 AsyncToken 行为:

http://code.google.com/p/swizframework/source/browse/trunk/src/main/flex/org/swizframework/util/TestUtil.as

Brian Kotek 有一篇内容非常丰富的博客文章,介绍了如何使用它来使用模拟委托来模拟服务器调用:

http://www.briankotek.com/blog/index.cfm/2009/3/16/Swiz-第 5 部分-使用模拟 AsyncToken 模拟服务器调用

Swiz framework's TestUtil class has some really cool ways for mocking AsyncToken behavior:

http://code.google.com/p/swizframework/source/browse/trunk/src/main/flex/org/swizframework/util/TestUtil.as

Brian Kotek has a very informative blog post on how to use it to simulate server calls using mock delegates:

http://www.briankotek.com/blog/index.cfm/2009/3/16/Swiz-Part-5-Simulating-Server-Calls-with-a-mock-AsyncToken

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