这是出于什么考虑,对比其他的语言,一般都会有一个默认超时时间。难道说是因为异步的这些东西就让程序员自己控制么?
还是说有超时,但是我不会用?
1
ixiaohei 2015 年 8 月 28 日
回调机制模式的东西能设置超时么?求高手解答
|
2
loveyu OP |
4
morethansean 2015 年 8 月 28 日
因为这个 API 比较简陋。
|
5
kfll 2015 年 8 月 28 日 via iPhone
|
6
whimsySun 2015 年 8 月 28 日 所以可以用 request 和 superagent
|
7
cheng007 2015 年 8 月 28 日
你自己封装一个超时 get ?代码类似于下面,代码只供参考, JS 的 API 我记得不熟悉,思路大致如此
function get (url, timeout, next ) { var is_timeout = false; setTimeout (timeout, function () { is_timeout = true; }) request.get (url, function (err, data ) { if (is_timeout ) { return next (new Error ("timeout")); } next (err, data ); }); } |