With the current system, a req is retried infinitely until we get a success response. Accepting a timeout would be good to break the loop of retrying.
Faced this recently when writing a few jest tests, where I wanted the request to succeed but only wait for a certain time and let the request timeout after that.
Something like this?
const main = () => {
const request = http.request(
{ method, port: options.port, path: options.path, timeout: 5000 },
(response) => {
if (response.statusCode === 200) {
return resolve({ started: true });
}
return main();
},
);
request.on('error', main);
request.on('timeout', () => {
request.destroy();
return resolve({ started: false });
});
request.end();
};
main();
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too