node.js - nodejs的http.get超时问题以及“装饰器”问题
伊谢尔伦
伊谢尔伦 2017-04-17 11:09:34
0
2
775

我用nodejs 进行http.get请求时,发现遇到无效网址,往往会出现卡死,经过google发现http.get好像不能设置超时,google到设置超时也有其他方法,可是我一个新手,对于那些代码看得不太懂,希望大家同通俗易懂说说这个的问题

关于"装饰器"是由python中引申出来的,是另一个问题,比如计算一个函数执行时间,在python中写一个caculateTime装饰器,很容易做到这一点,而且复用性也很高。现在我在nodejs想要实现类似的功能,nodejs有没有类似的语法特性或解决方案?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
黄舟
@decorator
def func():
  pass

is equivalent to

def func():
  pass
func = decorator(func)

So in JavaScript you can write:

var func = function(){};
func = decorator(func);
PHPzhong

process.hrtime() is used to calculate function execution time.

As for the first question, you need to listen to socket events, then handle socket.setTimeout() to set the timeout, and listen to tiemout to execute the timeout callback.

Http request is based on socket, please check the relevant documentation.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template