gpt4 book ai didi

javascript - 如果花费的时间太长,NodeJS 函数会超时吗?

转载 作者:行者123 更新时间:2023-11-30 08:25:25 25 4
gpt4 key购买 nike

我有一些第三方 API,它们运行的​​函数大约需要 30 分钟才能返回结果(它们会进行一些冗长的计算)。现在,如果我使用 Nodejs 通过适当的回调调用这样的 API,Nodejs 会默认等待 30 分钟让函数返回结果还是会超时?如果超时,有没有办法增加等待时间?

最佳答案

我假设你使用的是 express 如果你使用的是 express 你可以添加下面的代码来增加等待时间。

var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
server.timeout = 1000;

否则你可以使用纯 http

var http = require('http');
var server = http.createServer(function (req, res) {
setTimeout(function() {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}, 200);
}).listen(1337, '127.0.0.1');

server.timeout = 20;

关于javascript - 如果花费的时间太长,NodeJS 函数会超时吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46420538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com