ASyncToken 有什么意义?

发布于 2024-10-11 20:07:27 字数 888 浏览 0 评论 0原文

我的任务是为 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 技术交流群。

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

发布评论

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

评论(3

甜警司 2024-10-18 20:07:27

有两点值得注意:

  1. 您可以为 AsyncToken 分配多个响应者;
  2. 您可以绑定 AsyncToken 的结果。

您可能会发现这两件事很有用,具体取决于您正在使用的数据类型......而且可能还有更多的事情。

Two things stand out:

  1. You can assign more than one responder to an AsyncToken;
  2. You can bind the result of the AsyncToken.

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.

悲歌长辞 2024-10-18 20:07:27

对于更复杂的应用程序,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.

百变从容 2024-10-18 20:07:27
public function mssqlQuery(sql:String,fid:String) : void {
    var http:HTTPService = new HTTPService;
    var parm:Object = new Object;
    parm.fas_sql = sql;
    parm.fas_db = mssql_db; 
    http.url = mssql_url+"?irand="+Math.random();
    http.showBusyCursor = true;
    http.request = sql;
    http.addEventListener(ResultEvent.RESULT, mssqlResult);
    http.addEventListener(FaultEvent.FAULT, mssqlFault);
    http.method = "POST";
    sqlToken = http.send(parm);
    sqlToken.param = fid;
}
public function mssqlQuery(sql:String,fid:String) : void {
    var http:HTTPService = new HTTPService;
    var parm:Object = new Object;
    parm.fas_sql = sql;
    parm.fas_db = mssql_db; 
    http.url = mssql_url+"?irand="+Math.random();
    http.showBusyCursor = true;
    http.request = sql;
    http.addEventListener(ResultEvent.RESULT, mssqlResult);
    http.addEventListener(FaultEvent.FAULT, mssqlFault);
    http.method = "POST";
    sqlToken = http.send(parm);
    sqlToken.param = fid;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文