Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
}
Comment

fetch timeout

function timeoutFetch(promise) {
    return new Promise(function (resolve, reject) {
        setTimeout(function () {
            reject(new Error("timeout"))
        }, 5000)
        promise.then(resolve, reject)
    })
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: what is a node 
Javascript :: Using Props With React: With Props 
Javascript :: angular mat side nav 
Javascript :: react hooks useeffect 
Javascript :: usereducer in react 
Javascript :: chrome dev tools console api 
Javascript :: new keyword in js 
Javascript :: jquery val style 
Javascript :: react datetime mannual editing 
Javascript :: you are working on javascript project.what you used to restart the innermost loop 
Javascript :: mapview hooks glitch 
Javascript :: sql result to javascript array 
Javascript :: javascript random alphanumeric string 
Javascript :: cuantos docentes hay en mexico 
Javascript :: moment_timezone_1.default(...).tz(...).format is not a function 
Javascript :: js palindrome number 
Javascript :: immutablejs update use 
Javascript :: nodejs validate bnb wallet address 
Javascript :: theme ui currentcolor 
Javascript :: how to create a function with a display greeting 
Javascript :: await zoomus.joinmeeting crashing app react native 
Javascript :: check if item is already registered in angular angularfire site:stackoverflow.com 
Javascript :: deutsches ajax framework 
Javascript :: how to connect next js with postgresql localhost 
Javascript :: unexpected template string expression no-template-curly-in-string react 
Javascript :: cara-membuat-post-vi…ounter-di.html:1440 get https://bloggertut.googlecode.com/svn/trunk/js/highlight.pack.js net::err_aborted 404 
Javascript :: how to store textbox data while typing for chrome extension 
Javascript :: making js local function globally accessible 
Javascript :: show data of mongoose in html page using ejs 
Javascript :: javascript loop exec function 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =