-
-
Notifications
You must be signed in to change notification settings - Fork 12
Closed
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
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();Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed