查找有关如何实现返回AsyncToken的方法的示例或文档链接。
注意:这不是关于使用/消费返回AsyncToken的方法!我希望自己编写这样的方法。
发布于 2009-10-22 01:41:10
实现一个返回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;
}请注意,您不能实际使用applyResult和applyFault方法,因为当响应器不包含result或Event对象时,它们会向响应器传递一个错误。
发布于 2009-12-26 17:10:58
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-Part-5-Simulating-Server-Calls-with-a-mock-AsyncToken
https://stackoverflow.com/questions/1052858
复制相似问题