mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
1e7b37d1cc
There were two competing utility functions for calling fetch with a timeout. They have been combined into one.
24 lines
529 B
JavaScript
24 lines
529 B
JavaScript
const fetchWithTimeout = ({ timeout = 120000 } = {}) => {
|
|
return async function _fetch (url, opts) {
|
|
const abortController = new AbortController()
|
|
const abortSignal = abortController.signal
|
|
const f = fetch(url, {
|
|
...opts,
|
|
signal: abortSignal,
|
|
})
|
|
|
|
const timer = setTimeout(() => abortController.abort(), timeout)
|
|
|
|
try {
|
|
const res = await f
|
|
clearTimeout(timer)
|
|
return res
|
|
} catch (e) {
|
|
clearTimeout(timer)
|
|
throw e
|
|
}
|
|
}
|
|
}
|
|
|
|
export default fetchWithTimeout
|