Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSS

Timeout for a fetch

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  
  });
  clearTimeout(id);
  return response;
}
Source by dmitripavlutin.com #
 
PREVIOUS NEXT
Tagged: #Timeout #fetch
ADD COMMENT
Topic
Name
1+3 =