Last active
June 4, 2019 16:45
-
-
Save cms/4d1a101645cea74f199f1896c2ccc727 to your computer and use it in GitHub Desktop.
fetch with cancellation at timeout using AbortController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function fetchWithTimeout(url, options, timeout = 3000) { | |
const controller = new AbortController() | |
const { signal } = controller | |
setTimeout(() => controller.abort(), timeout) | |
return fetch(url, { ...options, signal }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment