ASyncToken 有什么意义?
我的任务是为 HTML5 WebSocket 服务器创建 AS3 客户端。
我最初的想法是使用 AS3 中的一些现有类来创建此服务,即尝试模拟 RemoteObject,但是经过研究,我真的看不到 ASyncToken 的意义!
我知道令牌被用作服务器调用及其响应之间的某种形式的引用,但我只是看不到它在哪里/如何成为唯一标识符。
以这段简短的代码为例:
var token:AsyncToken = myService.myCall(params);
news.addResponder(new Responder(onResult, onFault));
function onResult(event:ResultEvent) {
// do stuff
}
function onFault(event:FaultEvent) {
// do stuff
}
显然令牌有自己的响应者,并且服务可以保留令牌消息的字典,但是如果我在任一响应之前调用 myService.myCall 两次,服务是否知道哪个令牌将响应与?该服务是否创建一个唯一的标识符来将响应关联回令牌,或者在这些情况下会失败?
如果它确实在内部存储自己的唯一调用标识符,那么它会比完全跳过令牌并在调用参数中传递响应者更好吗?例如
myResponder = new Responder(onResult, onFault);
myService.myCall(myIResponder, <additional params>);
function onResult(event:ResultEvent) {
// do stuff
}
function onFault(event:FaultEvent) {
// do stuff
}
I've been tasked with the creation of an AS3 client for an HTML5 WebSocket server.
My initial thinking is to create this service using some of the existing classes in AS3, namely attempting to emulate RemoteObject, but having looked into it, I can't really see the point of the ASyncToken!
I understand the token is used as some form of reference between the server call and its response, but I just can't see where/how it becomes a unique identifier.
Take this short piece of code for example:
var token:AsyncToken = myService.myCall(params);
news.addResponder(new Responder(onResult, onFault));
function onResult(event:ResultEvent) {
// do stuff
}
function onFault(event:FaultEvent) {
// do stuff
}
Obviously the token has its own responder, and the service can keep a dictionary of tokens-messages, but if I were to call myService.myCall twice, before either responds, would the service know which token to associate the response with? Does the service create a unique identifier to associate the response back to the token, or would it fail under these circumstances?
If it does internally store its own unique identifier for calls, how would it be any better than skipping the token entirely and passing the responder in the call parameters? E.g.
myResponder = new Responder(onResult, onFault);
myService.myCall(myIResponder, <additional params>);
function onResult(event:ResultEvent) {
// do stuff
}
function onFault(event:FaultEvent) {
// do stuff
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有两点值得注意:
您可能会发现这两件事很有用,具体取决于您正在使用的数据类型......而且可能还有更多的事情。
Two things stand out:
You might find these two things useful depending on what kind of data you're working with... Also there might be more to it than this.
对于更复杂的应用程序,AsyncToken 让您可以更灵活地选择使用哪些函数/闭包/方法来接收数据或处理错误。
For more complicated applications, the AsyncToken lets you have a bit more flexibility in what functions/closures/methods to the reception of data, or handling errors.