请教老赵如何将http.get绑定为Jscex中标准的Task对象?

24 views
Skip to first unread message

xieren58

unread,
Jul 28, 2012, 2:22:56 PM7/28/12
to js...@googlegroups.com
RT,我用fromCallback这个来绑定,貌似没成功~~~

Jeffrey Zhao

unread,
Jul 30, 2012, 10:44:52 AM7/30/12
to js...@googlegroups.com
这个get方法是这么使用的:
 
http.get("http://www.google.com/index.html", function(res) {
  console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});
 
真是一个奇怪的调用规则,这似乎只能手写了。
 
http.getAsync = function (options) {
    return Task.create(function (t) {
        http.get(options, function (res) {
            t.complete(“success”, res);
        }).on(“error”, function (ex) {
            t.complete(“failure”, ex);
        });
    });
};
 
随手写的,没有测试过,自己调调看,有问题再来讨论。:)
 
 
From: xieren58
Sent: Sunday, July 29, 2012 2:22 AM
Subject: [jscex] 请教老赵如何将http.get绑定为Jscex中标准的Task对象?
 
RT,我用fromCallback这个来绑定,貌似没成功~~~

xieren58

unread,
Jul 30, 2012, 1:32:35 PM7/30/12
to js...@googlegroups.com
试了下,成功,感谢老赵,这个可以catch error, fromCallback 貌似不行~



在 2012年7月30日星期一UTC+8下午10时44分52秒,Jeffrey Zhao写道:

Jeffrey Zhao

unread,
Jul 30, 2012, 9:15:22 PM7/30/12
to js...@googlegroups.com
可以看下文档,fromCallback是不负责错误处理的,自然不适合用在这里。
--
 
 
 
Reply all
Reply to author
Forward
0 new messages