@大卫·艾博,你的建议很有帮助。从您发布的链接中,我可以使用http代理来限制套接字池。运行需要一段时间,但现在没有请求超时。
const cp = require('child_process');
const request = require('request');
const http = require('http');
module.exports = function (context, myTimer) {
context.log('Starting with agent');
const pool = new http.Agent();
pool.maxSockets = 4;
function doCall(cb) {
const url = 'https://jsonplaceholder.typicode.com/posts';
request({ url, pool }, (err) => {
if (err) {
context.log("error: " + err.toString());
}
cb();
});
}
let i = 500;
doCall(function iterate() {
if (i-- > 0) {
context.log('iterate ' + i);
doCall(iterate);
} else {
context.log('done');
context.done();
}
});
};