Really needs a timeout option
See original GitHub issueThis 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:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can you add it to the spec?
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.