查找有关如何实现返回AsyncToken的方法的示例或文档链接.
请注意,这不是关于使用/使用返回AsyncToken的方法!我希望自己写这些方法.
最佳答案 实现返回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方法,因为它们将响应者传递给Event,当响应者除了结果或fault对象时.