-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing timeout support #19
Comments
Indeed, good catch. |
@developit I think we can pick this up after request cancellation feature is done. Since fetch does not support timeout (I don't know if One way to implement this is when the But there is a catch, If and while passing singnal to fetch we'll have to do it this way I think I don't know if there is a simpler way to implement this, I'll be happy if there is a simpler way with less code. |
I've also good experience of using AbortController. Here is a full code example of utility function implementing the timeout: /** fetch('chatoptions/waittime', { @param { number } timeout - abort time (timeout) in seconds const abortController = new AbortController(); return abortController.signal; |
For those who will come here, i'll leave examples of using type script code and code. const fetchWithTimeout =
(timeoutMs: number) =>
(input: RequestInfo, init?: RequestInit): Promise<Response> => {
return fetch(input, {
...init,
signal: abortFetchSignal(timeoutMs),
})
}
const abortFetchSignal = (timeoutMs: number) => {
if (typeof window === 'undefined' || window.AbortController === undefined) {
return undefined
}
const abortController = new AbortController()
setTimeout(() => abortController.abort(), timeoutMs)
return abortController.signal
}
// Usage #1
redaxios.create({
fetch: fetchWithTimeout(1000),
})
// Usage #2
redaxios.get('~~', {
fetch: fetchWithTimeout(1000),
})
// Usage #3
export const axios = redaxios.create({
fetch: fetchWithTimeout(1000),
}) as typeof redaxios |
hi, this is VERY useful feature, when this ll be supported in options? |
I don't see that the axios timeout config is supported.
The text was updated successfully, but these errors were encountered: