[Feature] Request timeout #42
Replies: 4 comments
-
Would we want to supply a default in the class or set it so that the class is 0 to begin with and if that is the number present, when building up the config it ignores adding a AbortSignal. or should the function also toggle a flag as well as setting the milliseconds. |
Beta Was this translation helpful? Give feedback.
-
@ageddesi there is additional functionality I want to achieve with this feature. I want to give the option for developers to manually abort the request. According to mdm web docs, you can abort a fetch with timeout or explicit abort. Code exampleconst controller = new AbortController();
const timeoutSignal = AbortSignal.timeout(5000);
const res = await fetch(url, {
// This will abort the fetch when either signal is aborted
signal: AbortSignal.any([controller.signal, timeoutSignal]),
}); FunctionalityThe functionality we want to achieve for the HTTP Client are as follows:
Code exampleimport { HttpClient } from '@wolfpackthatcodes/http-client';
const httpClient = new HttpClient()
.timeout(3000);
abortBtn.addEventListener("click", () => {
httpClient.abort();
});
refreshBtn.addEventListener("click", () => {
httpClient.get('https://api.example.local/users');
}); |
Beta Was this translation helpful? Give feedback.
-
While implementing this feature, there is a limitation of browser compatibility for the Due to this limitation, we cannot combine the |
Beta Was this translation helpful? Give feedback.
-
I have created a PR #133 |
Beta Was this translation helpful? Give feedback.
-
Summary
Provide a
timeout
method that specifies the maximum number of milliseconds to wait for a response.Possible implementation
We can provide the
AbortSignal:timeout()
static method in the fetch() API options. The method returns an AbortSignal that will automatically abort after a specified time.Code example
For more information about
AbortSignal:timeout()
static method, read mdm web docs.Method signature
We can have a
timeout
method that accepts the maximum number of milliseconds the request should wait for a response.Code examples
Beta Was this translation helpful? Give feedback.
All reactions