Skip to content

Instantly share code, notes, and snippets.

View rfa404's full-sized avatar

Roman Kashtanov rfa404

View GitHub Profile
@rfa404
rfa404 / fetchWithTimeout.js
Created October 28, 2020 06:33
Fetch with timeout
async function fetchWithTimeout(resource, options) {
const { timeout = 8000 } = options;
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
const response = await fetch(resource, {
...options,
signal: controller.signal
});