question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Really needs a timeout option

See original GitHub issue

This library needs the ability to provide a timeout interval as part of the options object:

fetch('/users', {
  method: 'POST',
  timeout: 1000,
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Hubot',
    login: 'hubot',
  })
})

which is then internally assigned to the xhr object xhr.timeout = 1000 (property details here).

I’m having to do this, which feels over-the-top:

function promiseTimeout(ms, promise){

  return new Promise(function(resolve, reject){

    // create a timeout to reject promise if not resolved
    var timer = setTimeout(function(){
        reject(new Error("promise timeout"));
    }, ms);

    promise
        .then(function(res){
            clearTimeout(timer);
            resolve(res);
        })
        .catch(function(err){
            clearTimeout(timer);
            reject(err);
        });
  });
};
promiseTimeout(1000, fetch('https://courseof.life/johndoherty.json'))
   .then(function(cvData){
      alert(cvData);
   })
   .catch(function(){
      alert('request either failed or timedout');
   });

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
DinoSourcesRexcommented, Mar 15, 2017

Can you add it to the spec?

2reactions
mislavcommented, Oct 7, 2016

Yes you’re doing it right: https://github.com/github/fetch/issues/175#issuecomment-125779262

We can’t add a timeout option since it’s not in the spec.

Read more comments on GitHub >

github_iconTop Results From Across the Web

You Need a Timeout! - Honey Tree Preschool
Consider the benefits of taking time to yourself. In an article discussing the benefits of taking adult timeouts (article link below) Pollack ...
Read more >
Psychology Tools: How to Take a "Time Out" | HealthyPsych.com
Taking a “time-out” is a classic, anger management tool, but it can also be applied to any other heightened emotional state. 5 step-by-step...
Read more >
Steps | Time-Out | Essentials | Parenting Information - CDC
When children misbehave and parents try to correct them, feelings and emotions can get out of control. A time-out allows the parent and...
Read more >
Timeout on a Build Step of Jenkins - Stack Overflow
pipeline { agent any options { timeout(time: 1, unit: 'HOURS') // timeout on whole ... your build on any machine if you need...
Read more >
Do you need to call a timeout? "Don't just write aimlessly from ...
Anthony Brown shares how his songwriting changed by setting time aside and asking a simple question. God, what do you want me to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found