reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

Document timeout option

Open aamirafridi opened this issue 9 years ago • 1 comments

This lib supports timeout but not documented anywhere. https://github.com/ded/reqwest/blob/master/src/reqwest.js#L261-L285

aamirafridi avatar Feb 12 '16 15:02 aamirafridi

Shouldn't the timeout option set XMLHttpRequest.timeout instead of doing a setTimeout() hack? According to MDN:

The XMLHttpRequest.timeout property is an unsigned long representing the number of milliseconds a request can take before automatically being terminated.

One big edge-case to code around:

In Internet Explorer, the timeout property may be set only after calling the open() method and before calling the send() method.

var xhr = new XMLHttpRequest();
xhr.open('GET', '/server', true);

// Timeout must be set after calling open(). Thanks Internet Explorer.
xhr.timeout = 2000; // Time in milliseconds

xhr.onload = function () {
  // Request finished. Do processing here.
};

xhr.ontimeout = function (e) {
  // XMLHttpRequest timed out. Do something here.
};

xhr.send(null);

nodesocket avatar May 02 '16 00:05 nodesocket