我用nodejs 进行http.get
请求时,发现遇到无效网址,往往会出现卡死,经过google发现http.get
好像不能设置超时,google到设置超时也有其他方法,可是我一个新手,对于那些代码看得不太懂,希望大家同通俗易懂说说这个的问题
关于"装饰器"是由python中引申出来的,是另一个问题,比如计算一个函数执行时间,在python中写一个caculateTime装饰器,很容易做到这一点,而且复用性也很高。现在我在nodejs想要实现类似的功能,nodejs有没有类似的语法特性或解决方案?
is equivalent to
So in JavaScript you can write:
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.